hopefully fix failing recurring todos test. Timezones are a pain to get right

This commit is contained in:
Reinier Balt 2011-11-16 22:05:06 +01:00
parent 833297b355
commit 4b6aff5502
3 changed files with 97 additions and 95 deletions

View file

@ -177,9 +177,9 @@ class ApplicationController < ActionController::Base
def create_todo_from_recurring_todo(rt, date=nil) def create_todo_from_recurring_todo(rt, date=nil)
# create todo and initialize with data from recurring_todo rt # create todo and initialize with data from recurring_todo rt
todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id}) todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id})
todo.recurring_todo_id = rt.id
# set dates # set dates
todo.recurring_todo_id = rt.id
todo.due = rt.get_due_date(date) todo.due = rt.get_due_date(date)
show_from_date = rt.get_show_from_date(date) show_from_date = rt.get_show_from_date(date)

View file

@ -737,8 +737,9 @@ class RecurringTodo < ActiveRecord::Base
protected protected
def determine_start(previous, offset=0.day) # Determine start date to calculate next date for recurring todo
# offset needs to be 1.day for daily patterns # offset needs to be 1.day for daily patterns
def determine_start(previous, offset=0.day)
if previous.nil? if previous.nil?
start = self.start_from.nil? ? Time.zone.now : self.start_from start = self.start_from.nil? ? Time.zone.now : self.start_from
@ -747,12 +748,11 @@ class RecurringTodo < ActiveRecord::Base
else else
start = previous + offset start = previous + offset
unless self.start_from.nil?
# check if the start_from date is later than previous. If so, use # check if the start_from date is later than previous. If so, use
# start_from as start to search for next date # start_from as start to search for next date
start = self.start_from if self.start_from > previous start = self.start_from if ( self.start_from && self.start_from > previous )
end
end end
return start return start
end end

View file

@ -530,7 +530,9 @@ class TodosControllerTest < ActionController::TestCase
# check that the new_todo is in the tickler to show next month # check that the new_todo is in the tickler to show next month
assert !new_todo.show_from.nil? assert !new_todo.show_from.nil?
next_month = today + 1.month # do not use today here. It somehow gets messed up with the timezone calculation.
next_month = (Time.zone.now + 1.month).at_midnight
assert_equal next_month.utc.to_date.to_s(:db), new_todo.show_from.utc.to_date.to_s(:db) assert_equal next_month.utc.to_date.to_s(:db), new_todo.show_from.utc.to_date.to_s(:db)
end end