mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
fix #1002. every nth week was off by one week for recurring weekly todos. Thanks Thomas for spotting this.
Updated the wrong test too.
This commit is contained in:
parent
8bc3a484b2
commit
5c25e4569e
3 changed files with 13 additions and 9 deletions
|
|
@ -61,7 +61,7 @@ class RecurringTodo < ActiveRecord::Base
|
|||
errors.add_to_base("Every other nth week may not be empty for recurrence setting")
|
||||
end
|
||||
something_set = false
|
||||
%w{sunday monday tuesday wednesday thursday friday}.each do |day|
|
||||
%w{sunday monday tuesday wednesday thursday friday saturday}.each do |day|
|
||||
something_set ||= self.send("on_#{day}")
|
||||
end
|
||||
errors.add_to_base("You must specify at least one day on which the todo recurs") if !something_set
|
||||
|
|
@ -406,9 +406,9 @@ class RecurringTodo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def recurrence_pattern
|
||||
return "invalid repeat pattern" if every_other1.nil?
|
||||
case recurring_period
|
||||
when 'daily'
|
||||
return "invalid repeat pattern" if every_other1.nil?
|
||||
if only_work_days
|
||||
return "on work days"
|
||||
else
|
||||
|
|
@ -419,21 +419,19 @@ class RecurringTodo < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
when 'weekly'
|
||||
return "invalid repeat pattern" if every_other1.nil?
|
||||
if every_other1 > 1
|
||||
return "every #{every_other1} weeks"
|
||||
else
|
||||
return 'weekly'
|
||||
end
|
||||
when 'monthly'
|
||||
return "invalid repeat pattern" if every_other1.nil? || every_other2.nil?
|
||||
return "invalid repeat pattern" if every_other2.nil?
|
||||
if self.recurrence_selector == 0
|
||||
return "every #{self.every_other2} month#{self.every_other2>1?'s':''} on day #{self.every_other1}"
|
||||
else
|
||||
return "every #{self.xth} #{self.day_of_week} of every #{self.every_other2} month#{self.every_other2>1?'s':''}"
|
||||
end
|
||||
when 'yearly'
|
||||
return "invalid repeat pattern" if every_other1.nil?
|
||||
if self.recurrence_selector == 0
|
||||
return "every year on #{self.month_of_year} #{self.every_other1}"
|
||||
else
|
||||
|
|
@ -553,8 +551,8 @@ class RecurringTodo < ActiveRecord::Base
|
|||
start = previous + 1.day
|
||||
if start.wday() == 0
|
||||
# we went to a new week , go to the nth next week and find first match
|
||||
# that week
|
||||
start += self.every_other1.week
|
||||
# that week. Note that we already went into the next week, so -1
|
||||
start += (self.every_other1-1).week
|
||||
end
|
||||
unless self.start_from.nil?
|
||||
# check if the start_from date is later than previous. If so, use
|
||||
|
|
|
|||
2
test/fixtures/recurring_todos.yml
vendored
2
test/fixtures/recurring_todos.yml
vendored
|
|
@ -64,7 +64,7 @@ call_bill_gates_every_workday:
|
|||
show_from_delta: ~
|
||||
recurring_period: daily
|
||||
recurrence_selector: ~
|
||||
every_other1: ~
|
||||
every_other1: 1
|
||||
every_other2: ~
|
||||
every_other3: ~
|
||||
every_day: ~
|
||||
|
|
|
|||
|
|
@ -124,7 +124,9 @@ class RecurringTodoTest < ActiveSupport::TestCase
|
|||
due_date = @weekly_every_day.get_due_date(@sunday)
|
||||
assert_equal @monday, due_date
|
||||
|
||||
# saturday is last day in week, so the next date should be sunday + n_weeks
|
||||
# saturday is last day in week, so the next date should be sunday + n-1 weeks
|
||||
# n-1 because sunday is already in the next week
|
||||
@weekly_every_day.every_other1 = 3
|
||||
due_date = @weekly_every_day.get_due_date(@saturday)
|
||||
assert_equal @sunday + 2.weeks, due_date
|
||||
|
||||
|
|
@ -141,6 +143,10 @@ class RecurringTodoTest < ActiveSupport::TestCase
|
|||
assert_equal @wednesday, due_date
|
||||
due_date = @weekly_every_day.get_due_date(@wednesday)
|
||||
assert_equal @tuesday+1.week, due_date
|
||||
|
||||
@weekly_every_day.every_day = ' s'
|
||||
due_date = @weekly_every_day.get_due_date(@sunday)
|
||||
assert_equal @saturday+1.week, due_date
|
||||
end
|
||||
|
||||
def test_monthly_pattern
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue