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:
parent
26862ed2ef
commit
b12d78bdb2
10
stoptime.rb
10
stoptime.rb
|
@ -349,12 +349,22 @@ module StopTime::Models
|
||||||
belongs_to :task
|
belongs_to :task
|
||||||
has_one :customer, :through => :task
|
has_one :customer, :through => :task
|
||||||
|
|
||||||
|
before_validation :round_start_end
|
||||||
|
|
||||||
# Returns the total amount of time, the duration, in hours (up to
|
# Returns the total amount of time, the duration, in hours (up to
|
||||||
# 2 decimals only!).
|
# 2 decimals only!).
|
||||||
def hours_total
|
def hours_total
|
||||||
((self.end - self.start) / 1.hour).round(2)
|
((self.end - self.start) / 1.hour).round(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#########
|
||||||
|
protected
|
||||||
|
|
||||||
|
def round_start_end
|
||||||
|
self.start = round_time(self.start)
|
||||||
|
self.end = round_time(self.end)
|
||||||
|
end
|
||||||
|
|
||||||
#######
|
#######
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue