Quartz error Sunday written as 0
Day-of-Week values must be between 1 and 7
java.lang.RuntimeException: CronExpression '0 0 9 ? * 0' is invalid.
Caused by: java.text.ParseException: Day-of-Week values must be between 1 and 7Message produced by running the expression through org.quartz.CronExpression from Quartz 2.5.2.
What it means
Quartz numbers the days of the week from 1 to 7, with 1 = Sunday and 7 = Saturday. Unix cron, Kubernetes, GitHub Actions and Azure use 0 for Sunday, so a 0 copied from one of those is out of range here.
The quieter problem is the expressions that don’t fail. 1-5, which is Monday to Friday in Unix cron, is valid in Quartz and means Sunday to Thursday. Day names (SUN to SAT) mean the same thing everywhere, so they are the safer choice.
Rejected expressions and their fixes
Each expression opens in the tester. The message under a rejected one is what Quartz 2.5.2 printed for it.
-
Use0 0 9 ? * SUNAt 09:00, on Sundays.
Sundays at 09:00.
1works too. -
Use0 0 9 ? * SAT,SUNAt 09:00, at weekends.
Weekends at 09:00. In Quartz numbers that is
1,7. -
Use0 0 9 ? * SUN-THUAt 09:00, on Sunday through Thursday.
Sunday to Thursday, written with names.
Questions
- Is Sunday 0, 1 or 7 in Quartz?
- Sunday is 1 and Saturday is 7, and 0 is not allowed. In Unix cron Sunday is 0, and most crons accept 7 too. EventBridge numbers days the way Quartz does.
- Why does my weekday schedule run on Sunday?
- Probably
1-5was copied from Unix cron. In Quartz that is Sunday to Thursday. UseMON-FRIor2-6.
Other Quartz errors
- Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.Quartz: Both day fields are set
- Unexpected end of expression.Quartz: Five fields instead of six
- '?' can only be specified for Day-of-Month -OR- Day-of-Week.Quartz:
?in the wrong place - Hour values must be between 0 and 23Quartz: A value out of range
- Increment >= 60 : 90Quartz: A step longer than the field
- Unexpected character: @Quartz:
@dailyand other shortcuts