fix(eventbridge,scheduler): read cron day-of-week as AWS 1-7 SUN-SAT (#3147)

Both schedule parsers built their cron definition with cron-utils' default
day-of-week field, which is Unix numbering: 0-6 for SUN-SAT. AWS numbers that
field 1-7 for SUN-SAT, so every numeric day was read one day late and Saturday
could not be expressed at all.

cron(0 12 ? * 2 *) is Monday to AWS and fired on Tuesday. AWS's own documented
example cron(15 10 ? * 6L 2022-2023), the last Friday of the month, fired on the
last Saturday. cron(0 12 ? * 7 *) did not parse at all, failing with "Value 7 not
in range [0, 6]". Day names were always correct, because cron-utils resolves them
against its own numbering, so only expressions written with numbers were wrong.

The definitions are at ScheduleExpressionParser.java:32 (eventbridge) and
SchedulerExpressionParser.java:55 (scheduler). Both now pin the field with
withValidRange(1, 7) and withMondayDoWValue(2), the same shape cron-utils uses
for Quartz, whose day-of-week dialect AWS follows. 7 parses as Saturday, and 0 is
rejected in line with AWS's documented 1-7 range.

The existing eventbridge test getNextFireTimeFirstMondayOfMonth encoded the old
behavior: it parsed cron(30 2 ? * 2#1 *), named itself for the first Monday, then
asserted the fire day was a Tuesday. It now asserts 2026-03-02, which is the
first Monday of that month.
This commit is contained in:
Max Freedom Pollard authored and GitHub committed 2026-09-06 18:41:17 -04:00
1 parent fd665a08cc
commit 60a8a9d252
5 files changed
+120 -8

No files matched your search

@@ -29,7 +29,11 @@ public final class ScheduleExpressionParser {
.withHours().and()
.withDayOfMonth().supportsHash().supportsL().supportsW().supportsQuestionMark().and()
.withMonth().and()
.withDayOfWeek().supportsHash().supportsL().supportsW().supportsQuestionMark().and()
// AWS numbers day-of-week 1-7 as SUN-SAT, not the Unix 0-6 SUN-SAT that cron-utils
// defaults to, so Monday is 2. Without this every numeric day fires one day late and
// 7 (Saturday) does not parse at all.
.withDayOfWeek().withValidRange(1, 7).withMondayDoWValue(2)
.supportsHash().supportsL().supportsW().supportsQuestionMark().and()
.withYear().optional().and()
.instance();
CRON_PARSER = new CronParser(definition);
@@ -52,7 +52,11 @@ public final class SchedulerExpressionParser {
.withHours().and()
.withDayOfMonth().supportsHash().supportsL().supportsW().supportsQuestionMark().and()
.withMonth().and()
.withDayOfWeek().supportsHash().supportsL().supportsW().supportsQuestionMark().and()
// AWS numbers day-of-week 1-7 as SUN-SAT, not the Unix 0-6 SUN-SAT that cron-utils
// defaults to, so Monday is 2. Without this every numeric day fires one day late and
// 7 (Saturday) does not parse at all.
.withDayOfWeek().withValidRange(1, 7).withMondayDoWValue(2)
.supportsHash().supportsL().supportsW().supportsQuestionMark().and()
.withYear().optional().and()
.instance();
CRON_PARSER = new CronParser(definition);