fix corner case for yearly repeating todos

also adds test for this case
This commit is contained in:
Reinier Balt 2008-10-14 10:57:12 +02:00
parent 1118a582d7
commit c64bbb9e60
2 changed files with 9 additions and 5 deletions

View file

@ -517,17 +517,18 @@ class RecurringTodo < ActiveRecord::Base
end
def get_yearly_date(previous)
start = determine_start(previous)
day = self.every_other1
month = self.every_other2
case self.recurrence_selector
when 0 # specific day of a specific month
# if there is no next month n in this year, search in next year
if start.month >= month
start = Time.zone.local(start.year+1, month, 1) if start.day >= day
start = Time.zone.local(start.year, month, 1) if start.day <= day
if start.month > month || (start.month == month && start.day > day)
# if there is no next month n and day m in this year, search in next year
start = Time.zone.local(start.year+1, month, 1)
else
# if there is a next month n, stay in this year
start = Time.zone.local(start.year, month, 1)
end
return Time.zone.local(start.year, month, day)

View file

@ -174,6 +174,9 @@ class RecurringTodoTest < Test::Rails::TestCase
# same month, day after
due_date = @yearly.get_due_date(@monday) # june 9th
assert_equal Time.zone.local(2009,6,8), due_date # june 8th next year
# very overdue
due_date = @yearly.get_due_date(@monday+5.months-2.days) # november 7
assert_equal Time.zone.local(2009,6,8), due_date # june 8th next year
@yearly.recurrence_selector = 1
@yearly.every_other3 = 2 # second