File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -757,16 +757,25 @@ function Date:apply_repeater()
757757 if not repeater then
758758 return self
759759 end
760+
761+ -- Repeater relative to completion time
760762 if repeater :match (' ^%.%+%d+' ) then
761- return date :set_todays_date ():adjust (repeater :sub (2 ))
763+ -- Strip the '.' from the repeater
764+ local offset = repeater :sub (2 )
765+ return date :set_todays_date ():adjust (offset )
762766 end
767+
768+ -- Repeater relative to deadline/scheduled date
763769 if repeater :match (' ^%+%+%d' ) then
764- while date .timestamp < current_time .timestamp do
765- date = date :adjust (repeater :sub (2 ))
766- end
770+ -- Strip the '+' from the repeater
771+ local offset = repeater :sub (2 )
772+ repeat
773+ date = date :adjust (offset )
774+ until date .timestamp > current_time .timestamp
767775 return date
768776 end
769777
778+ -- Simple repeat; apply repeater once to deadline/scheduled date
770779 return date :adjust (repeater )
771780end
772781
Original file line number Diff line number Diff line change @@ -571,6 +571,13 @@ describe('Date object', function()
571571 assert .are .same (inTwoWeeks :to_string (), sunday :apply_repeater_until (inTwoWeeks ):to_string ())
572572 end )
573573
574+ it (' should apply repeater to future dates' , function ()
575+ local tomorrow = Date .now ({ adjustments = { ' ++1d' } }):add ({ day = 1 })
576+ local day_after_tomorrow = tomorrow :add ({ day = 1 })
577+ local updated_date = tomorrow :apply_repeater ()
578+ assert .are .same (updated_date :to_string (), day_after_tomorrow :to_string ())
579+ end )
580+
574581 it (' should cache check for today' , function ()
575582 local today = Date .today ()
576583 assert .is .Nil (today .is_today_date )
You can’t perform that action at this time.
0 commit comments