From b12d78bdb2764bddb341b72d2c03f6b8a037bdb5 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sat, 25 Oct 2014 21:55:23 +0200 Subject: [PATCH] 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. --- stoptime.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index f8b1c79..7221dd7 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -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