From 97b6098bcda1c2c8a68caf4a3e49b089b98d842a Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 12 Oct 2014 17:04:18 +0200 Subject: [PATCH] Round total time of tasks to two decimals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes misrepresentation errors. This occus for example when a task has a length that would be represented using a floating point number that has more than 2 decimals. For example: a task of length 59 minutes (i.e. 0.9833333333333333... hour) is shown on the invoice as having a length of 0.98 hours while in calculations still the unrounded task length is used. When a hourly rate of €100 pe rhour is defined, the invoice will show: 0.98h x €100/h = €98.33. which is confusing and although correct given maximal accurancy, it will obviously not be accepted by book keeping programs. --- stoptime.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index b84d684..f8a289c 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -344,9 +344,10 @@ module StopTime::Models belongs_to :task has_one :customer, :through => :task - # Returns the total amount of time, the duration, in hours. + # Returns the total amount of time, the duration, in hours (up to + # 2 decimals only!). def hours_total - (self.end - self.start) / 1.hour + ((self.end - self.start) / 1.hour).round(2) end end