DevKitHub

Programming

Cron Dialect Converter — Unix, Quartz, AWS and Spring

Convert a cron expression between Unix, Quartz, AWS EventBridge and Spring, with the numbering differences applied rather than left to catch you.

In every dialect

Unix / crontab / Kubernetes
0 2 * * 1-5
Quartz (Java)
0 0 2 ? * 2-6
AWS EventBridge
0 2 ? * 2-6 *
Spring @Scheduled
0 0 2 * * 1-5

Fields as read

Minute
0
Hour
2
Day of month
*
Month
*
Day of week
1-5
  • Day-of-week is numeric. In the source dialect it means MON-FRI. Unix numbers days 0-6 from Sunday and Quartz and EventBridge number them 1-7 from Sunday, so the same digits mean a different set of days in each — this is where "1-5" silently becomes Sunday to Thursday. Using names instead of numbers removes the problem entirely.

This tool runs entirely in your browser. Your input is never uploaded, stored or logged.

How it works

The expression 0 0 * * 1-5 means Monday to Friday under Unix cron and Sunday to Thursday under Quartz and AWS EventBridge. Nothing errors. The job simply runs on the wrong days — including one day nobody is watching and one they are — and the expression passes review because it is correct, for the other scheduler. The cause is that Unix numbers days 0 to 6 from Sunday while Quartz and EventBridge number them 1 to 7 from Sunday, so every numeric day is off by one.

This converts between the four dialects with that shift applied, and leaves day names alone because MON means Monday everywhere — which is the practical advice the tool ends up giving most often. Numbers that are not days are left alone too: the occurrence count after a # in 6#2, and the interval after a slash in */2, are not weekdays and shifting them would corrupt the expression in a subtler way than the problem being fixed.

The second trap is field count. Quartz and Spring put seconds first, so a five-field Unix expression pasted into either shifts every field left — the minute becomes the second, the hour becomes the minute — and a job meant for 02:30 daily runs every minute. That is detected and explained rather than silently accepted. EventBridge’s requirement that exactly one of day-of-month and day-of-week be a question mark is handled too, along with the features that simply do not survive translation: Unix has no L, W or #, and saying so is more useful than emitting something that looks equivalent and is not.

Common problems

Every example below is run against this tool in our test suite, so what it says here is what the tool actually does.

A Quartz expression has 6 or 7 fields and this has 5.

0 2 *
Why:
The dialects take different numbers of fields. A five-field expression is Unix cron; Quartz and Spring add seconds at the front and EventBridge adds a year at the end.
Fix:
Pick the dialect that matches where the expression came from, then convert.

The job runs on the wrong days after moving scheduler.

Why:
Numeric day-of-week is off by one between Unix and Quartz or EventBridge. 1-5 is Monday to Friday in one and Sunday to Thursday in the other, and neither will complain.
Fix:
Convert with this tool, or write day names instead — MON-FRI means the same thing in every dialect.

A job runs far more often than the expression suggests.

Why:
Either a five-field expression was pasted into a scheduler expecting seconds first, or day-of-month and day-of-week are both restricted — Unix ORs those two fields rather than ANDing them.
Fix:
Check the field count first. If both day fields are set, restrict one and leave the other as *.

Frequently asked questions

Why does 1-5 mean different days in different schedulers?
Unix numbers days 0 to 6 starting at Sunday; Quartz and AWS EventBridge number them 1 to 7 starting at Sunday. So 1-5 is Monday to Friday in Unix and Sunday to Thursday in the others. Using names avoids the problem entirely.
What happens if I paste a Unix expression into Quartz?
Quartz expects seconds first, so every field shifts left. A job meant to run at 02:30 daily ends up running every minute. This converter detects the field count and explains it rather than accepting it.
Why does AWS need a question mark?
EventBridge requires exactly one of day-of-month and day-of-week to be ?, because constraining both is ambiguous. The converter inserts it where it can and says so when the expression constrains both genuinely.

Read more about this

Last updated