Skip to content

Commit dadf563

Browse files
Fixes a bug in completing future tasks (#470)
1 parent 1b8819b commit dadf563

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lua/orgmode/objects/date.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff 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)
771780
end
772781

tests/plenary/object/date_spec.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)