Skip to content

Commit 33c2afa

Browse files
authored
test: add test preventing 1W,2W regression (#9)
In versions previous to October 2024, 1W,2W and 1W,3W in DOM field would cause CRONs to trigger as often as possible from 1st to 2nd/3rd, as handle_w_dom() would always go to the 1st (and calculate from there) when it was in the checked W flag range, which starts up to 2 days before the current day. This bug was fixed unintentionally with the rework of W and L flag handling, but it would be good to include the tests to avoid regressions.
2 parents c2ca479 + 7d4ae23 commit 33c2afa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ccronexpr_test.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,26 @@ void test_expr() {
510510
assert(check_next("0 0 0 1,1W,15W * *", "2021-12-31_01:02:03", "2022-01-01_00:00:00"));
511511
assert(check_next("0 0 0 1,1W,15W * *", "2022-01-01_01:02:03", "2022-01-03_00:00:00"));
512512
assert(check_next("0 0 0 1,1W,15W * *", "2022-01-03_01:02:03", "2022-01-14_00:00:00"));
513+
// Testcase for new years eve bug
514+
assert(check_next("0 0 12 1W,2W * ?","2025-01-01_11:00:00", "2025-01-01_12:00:00"));
515+
assert(check_next("0 0 12 1W,2W * ?","2025-01-01_13:01:00", "2025-01-02_12:00:00"));
516+
assert(check_next("0 0 12 1W,2W * ?","2025-01-02_12:01:00", "2025-02-03_12:00:00"));
517+
assert(check_next("0 0 12 1W,3W * ?","2025-01-01_11:00:00", "2025-01-01_12:00:00"));
518+
assert(check_next("0 0 12 1W,3W * ?","2025-01-01_13:01:00", "2025-01-03_12:00:00"));
519+
assert(check_next("0 0 12 1W,3W * ?","2025-01-03_12:01:00", "2025-02-03_12:00:00"));
520+
assert(check_next("0 0 12 1W,15W * ?","2025-01-01_11:00:00", "2025-01-01_12:00:00"));
521+
assert(check_next("0 0 12 1W,15W * ?","2025-01-01_13:01:00", "2025-01-15_12:00:00"));
522+
assert(check_next("0 0 12 1W,15W * ?","2025-01-15_12:01:00", "2025-02-03_12:00:00"));
523+
// Repeat for 1st May, a thursday
524+
assert(check_next("0 0 12 1W,2W * ?","2025-05-01_11:00:00", "2025-05-01_12:00:00"));
525+
assert(check_next("0 0 12 1W,2W * ?","2025-05-01_13:01:00", "2025-05-02_12:00:00"));
526+
assert(check_next("0 0 12 1W,2W * ?","2025-05-02_12:01:00", "2025-06-02_12:00:00"));
527+
assert(check_next("0 0 12 1W,3W * ?","2025-05-01_11:00:00", "2025-05-01_12:00:00"));
528+
assert(check_next("0 0 12 1W,3W * ?","2025-05-01_13:01:00", "2025-05-02_12:00:00"));
529+
assert(check_next("0 0 12 1W,3W * ?","2025-05-02_12:01:00", "2025-06-02_12:00:00"));
530+
assert(check_next("0 0 12 1W,15W * ?","2025-05-01_11:00:00", "2025-05-01_12:00:00"));
531+
assert(check_next("0 0 12 1W,15W * ?","2025-05-01_13:01:00", "2025-05-15_12:00:00"));
532+
assert(check_next("0 0 12 1W,15W * ?","2025-05-15_12:01:00", "2025-06-02_12:00:00"));
513533
}
514534

515535
void test_parse() {

0 commit comments

Comments
 (0)