fix(recurrence): honor BYDAY for weekly RRULE expansion
CI / test (push) Successful in 8m33s
CI / deploy-ift (push) Successful in 3m26s
CI / e2e-ift (push) Successful in 3m44s
CI / deploy-stage (push) Successful in 2m14s
CI / e2e-stage (push) Successful in 1m21s

Expand weekdays in the DTSTART week and advance by Interval weeks from Monday;
add unit coverage for MO/WE/FR and mid-week starts.
This commit is contained in:
2026-08-01 18:17:23 +03:00
parent 0e4e886cd4
commit 0a5e86c4a0
2 changed files with 88 additions and 10 deletions
+25
View File
@@ -7,6 +7,7 @@ logic_recurrence_test_() ->
{"Validate RRULE test", fun test_validate_rrule/0},
{"Generate daily occurrences test", fun test_daily_occurrences/0},
{"Generate weekly occurrences test", fun test_weekly_occurrences/0},
{"Generate weekly BYDAY occurrences test", fun test_weekly_byday_occurrences/0},
{"Generate monthly occurrences test", fun test_monthly_occurrences/0},
{"Generate with count limit test", fun test_count_limit/0},
{"Generate with until limit test", fun test_until_limit/0}
@@ -71,6 +72,30 @@ test_weekly_occurrences() ->
?assertEqual({{2026, 4, 20}, {10, 0, 0}}, lists:nth(1, Occurrences)),
?assertEqual({{2026, 5, 11}, {10, 0, 0}}, lists:nth(4, Occurrences)).
test_weekly_byday_occurrences() ->
%% Monday start, MO/WE/FR for two weeks → 6 slots
StartTime = {{2026, 4, 20}, {10, 0, 0}},
RRule = #{
freq => <<"WEEKLY">>,
interval => 1,
byday => [<<"MO">>, <<"WE">>, <<"FR">>]
},
RangeEnd = {{2026, 5, 1}, {10, 0, 0}},
Occurrences = logic_recurrence:generate_occurrences(StartTime, RRule, RangeEnd),
?assertEqual(6, length(Occurrences)),
?assertEqual({{2026, 4, 20}, {10, 0, 0}}, lists:nth(1, Occurrences)),
?assertEqual({{2026, 4, 22}, {10, 0, 0}}, lists:nth(2, Occurrences)),
?assertEqual({{2026, 4, 24}, {10, 0, 0}}, lists:nth(3, Occurrences)),
?assertEqual({{2026, 4, 27}, {10, 0, 0}}, lists:nth(4, Occurrences)),
?assertEqual({{2026, 4, 29}, {10, 0, 0}}, lists:nth(5, Occurrences)),
?assertEqual({{2026, 5, 1}, {10, 0, 0}}, lists:nth(6, Occurrences)),
%% Mid-week DTSTART must not emit earlier weekdays of the same week
WedStart = {{2026, 4, 22}, {10, 0, 0}},
MidWeek = logic_recurrence:generate_occurrences(WedStart, RRule, {{2026, 4, 24}, {10, 0, 0}}),
?assertEqual([{{2026, 4, 22}, {10, 0, 0}}, {{2026, 4, 24}, {10, 0, 0}}], MidWeek).
test_monthly_occurrences() ->
StartTime = {{2026, 4, 20}, {10, 0, 0}},
RRule = #{