fix rounding problem

Fixes the rounding problem. Since entry.hours is an getter with integrated round(2), its result should not be used for spent time calculation. Given the update function is called quite often (every 1-2 minutes), especially when the redmine issue is open in browser, it can disrupt the resulting overall logged time by up to 50%.
This commit is contained in:
jan-imrich
2020-11-18 12:36:21 +01:00
committed by Jens Kraemer
parent 742157a1f1
commit 9802307e5e

View File

@@ -45,7 +45,7 @@ module Stopwatch
# timestamp to either nil (stop: true) or current time. # timestamp to either nil (stop: true) or current time.
def update(stop: false) def update(stop: false)
if hours = runtime_hours and entry = self.time_entry if hours = runtime_hours and entry = self.time_entry
time_entry.update_column :hours, entry.hours + hours time_entry.update_column :hours, entry.read_attribute(:hours) + hours
end end
data[:started_at] = stop || !running? ? nil : Time.now.to_i data[:started_at] = stop || !running? ? nil : Time.now.to_i
save save