Add private method for the TimeEntry model to round time

The method uses the configuration to determine the resolution and is
inspired by the following StackOverflow answer:
https://stackoverflow.com/a/4182700.
This commit is contained in:
Paul van Tilburg 2014-10-25 21:53:30 +02:00
parent b182711f39
commit 26862ed2ef
1 changed files with 15 additions and 0 deletions

View File

@ -354,6 +354,21 @@ module StopTime::Models
def hours_total
((self.end - self.start) / 1.hour).round(2)
end
#######
private
def round_time(t)
config = Config.instance
res = config["time_resolution"]
down = t - (t.to_i % res.minutes)
up = down + res.minutes
diff_down = t - down
diff_up = up - t
diff_down < diff_up ? down : up
end
end
# == The invoice class