From f7c0ffff1543cfe116f5392bddb9b3b341c0627b Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 16 Jun 2013 22:58:15 +0200 Subject: [PATCH] Add a day if the end time is before the start time (closes: #d96685) --- stoptime.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index 7eca5ae..b82af71 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1189,6 +1189,10 @@ module StopTime::Controllers :end => "#{@input.date} #{@input.end}", :comment => @input.comment, :bill => @input.has_key?("bill")) + # Add a day to the end date if the total hours is negative. + # It means that the end time was before the begin time, i.e. + # overnight. + @time_entry.end += 1.day if @time_entry.hours_total < 0 @time_entry.save if @time_entry.invalid? @errors = @time_entry.errors @@ -1268,6 +1272,8 @@ module StopTime::Controllers @time_entry.end = "#{@input["date"]} #{@input["end"]}" @time_entry.task = Task.find(@input.task) @time_entry.bill = @input.has_key? "bill" + # Add a day to the end date if the total hours is negative. + @time_entry.end += 1.day if @time_entry.hours_total < 0 @time_entry.save if @time_entry.invalid? @errors = @time_entry.errors