From c64bbb9e60defa4a96b33f1d8dc230870805efe8 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Tue, 14 Oct 2008 10:57:12 +0200 Subject: [PATCH] fix corner case for yearly repeating todos also adds test for this case --- app/models/recurring_todo.rb | 11 ++++++----- test/unit/recurring_todo_test.rb | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/recurring_todo.rb b/app/models/recurring_todo.rb index 86b24dae..0b103b03 100644 --- a/app/models/recurring_todo.rb +++ b/app/models/recurring_todo.rb @@ -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) diff --git a/test/unit/recurring_todo_test.rb b/test/unit/recurring_todo_test.rb index bd256eba..82ba1cb5 100644 --- a/test/unit/recurring_todo_test.rb +++ b/test/unit/recurring_todo_test.rb @@ -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