mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-28 12:58:48 +01:00
fix case with future start_from for other recurrence periods too
this patch belongs to previous
This commit is contained in:
parent
f4378ffde1
commit
88ea02d29a
2 changed files with 62 additions and 33 deletions
|
|
@ -34,23 +34,13 @@ class RecurringTodoTest < Test::Rails::TestCase
|
|||
def test_daily_every_day
|
||||
# every_day should return todays date if there was no previous date
|
||||
due_date = @every_day.get_due_date(nil)
|
||||
# use to_s in compare, because milisec could be different
|
||||
assert_equal @today.to_s, due_date.to_s
|
||||
# use strftime in compare, because milisec / secs could be different
|
||||
assert_equal @today.strftime("%d-%m-%y"), due_date.strftime("%d-%m-%y")
|
||||
|
||||
# when the last todo was completed today, the next todo is due tomorrow
|
||||
due_date =@every_day.get_due_date(@today)
|
||||
assert_equal @tomorrow, due_date
|
||||
|
||||
# every_day should return start_day if it is in the future
|
||||
@every_day.start_from = @in_three_days
|
||||
due_date = @every_day.get_due_date(nil)
|
||||
assert_equal @in_three_days, due_date
|
||||
|
||||
# if we give a date in the future for the previous todo, the next to do
|
||||
# should be based on that future date.
|
||||
due_date = @every_day.get_due_date(@in_four_days)
|
||||
assert_equal @in_four_days+1.day, due_date
|
||||
|
||||
|
||||
# do something every 14 days
|
||||
@every_day.every_other1=14
|
||||
due_date = @every_day.get_due_date(@today)
|
||||
|
|
@ -168,7 +158,6 @@ class RecurringTodoTest < Test::Rails::TestCase
|
|||
|
||||
due_date = @monthly.get_due_date(@sunday) # june 8th
|
||||
assert_equal Time.utc(2008,8,8), due_date # aug 8th
|
||||
|
||||
end
|
||||
|
||||
def test_yearly_pattern
|
||||
|
|
@ -206,10 +195,33 @@ class RecurringTodoTest < Test::Rails::TestCase
|
|||
end
|
||||
|
||||
def test_start_from_in_future
|
||||
# every_day should return start_day if it is in the future
|
||||
@every_day.start_from = @in_three_days
|
||||
due_date = @every_day.get_due_date(nil)
|
||||
assert_equal @in_three_days, due_date
|
||||
due_date = @every_day.get_due_date(@tomorrow)
|
||||
assert_equal @in_three_days, due_date
|
||||
|
||||
# if we give a date in the future for the previous todo, the next to do
|
||||
# should be based on that future date.
|
||||
due_date = @every_day.get_due_date(@in_four_days)
|
||||
assert_equal @in_four_days+1.day, due_date
|
||||
|
||||
@weekly_every_day.start_from = Time.utc(2020,1,1)
|
||||
assert_equal Time.utc(2020,1,1), @weekly_every_day.get_due_date(nil)
|
||||
assert_equal Time.utc(2020,1,1), @weekly_every_day.get_due_date(Time.utc(2019,10,1))
|
||||
assert_equal Time.utc(2020,1,10), @weekly_every_day.get_due_date(Time.utc(2020,1,9))
|
||||
|
||||
@monthly_every_last_friday.start_from = Time.utc(2020,1,1)
|
||||
assert_equal Time.utc(2020,1,31), @monthly_every_last_friday.get_due_date(nil) # last friday of jan
|
||||
assert_equal Time.utc(2020,1,31), @monthly_every_last_friday.get_due_date(Time.utc(2019,12,1)) # last friday of jan
|
||||
assert_equal Time.utc(2020,2,28), @monthly_every_last_friday.get_due_date(Time.utc(2020,2,1)) # last friday of feb
|
||||
|
||||
# start from after june 8th 2008
|
||||
@yearly.start_from = Time.utc(2008,6,12)
|
||||
assert_equal Time.utc(2009,6,8), @yearly.get_due_date(nil) # jun 8th next year
|
||||
assert_equal Time.utc(2009,6,8), @yearly.get_due_date(Time.utc(2008,6,1)) # also next year
|
||||
@yearly.start_from = Time.utc(2020,6,12)
|
||||
assert_equal Time.utc(2021,6,8), @yearly.get_due_date(nil) # jun 8th next year
|
||||
assert_equal Time.utc(2021,6,8), @yearly.get_due_date(Time.utc(2019,6,1)) # also next year
|
||||
assert_equal Time.utc(2021,6,8), @yearly.get_due_date(Time.utc(2020,6,15)) # also next year
|
||||
|
||||
this_year = Time.now.utc.year
|
||||
@yearly.start_from = Time.utc(this_year+1,6,12)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue