Round start and end time before validation (and thus saving)

I've chosen to connect the callback to before_validation because
at a later point we want to check for overlap between time entries
and this should be done using the corrected versions.
This commit is contained in:
Paul van Tilburg 2014-10-25 21:55:23 +02:00
parent 26862ed2ef
commit b12d78bdb2
1 changed files with 10 additions and 0 deletions

View File

@ -349,12 +349,22 @@ module StopTime::Models
belongs_to :task
has_one :customer, :through => :task
before_validation :round_start_end
# Returns the total amount of time, the duration, in hours (up to
# 2 decimals only!).
def hours_total
((self.end - self.start) / 1.hour).round(2)
end
#########
protected
def round_start_end
self.start = round_time(self.start)
self.end = round_time(self.end)
end
#######
private