This Javascript library provides support for translation of Spring Cron Expressions to human readable text (English, for now).
import translateSpringCronExpression from cron-expression-translator;
const inputCronString = "0 0 8-10/1 * * *";
const humanReadableText = translateSpringCronExpression(inputCronString);
// sample output : Every hour From the 8th to 10th hour, Every day of the month, Every month, Every day of the week
The Spring Cron Expression has 6 fields:
-
Second (0-59)
-
Minute (0 - 59)
-
Hour (0 - 23)
-
Day of the month (1 - 31)
-
Month (1 - 12) (or JAN-DEC)
-
Day of the week (0 - 7) (0 or 7 is Sunday, or MON-SUN)
-
A field may be an asterisk (*), which always stands for "first-last". For the "day of the month" or "day of the week" fields, a question mark (?) may be used instead of an asterisk.
-
Ranges of numbers are expressed by two numbers separated with a hyphen (-). The specified range is inclusive.
-
Following a range (or *) with /n specifies the interval of the number's value through the range.
-
English names can also be used for the "month" and "day of week" fields. Use the first three letters of the particular day or month (case does not matter).
-
The "day of month" and "day of week" fields can contain a L-character, which stands for "last", and has a different meaning in each field:
-
In the "day of month" field, L stands for "the last day of the month". If followed by an negative offset (i.e. L-n), it means "nth-to-last day of the month". If followed by W (i.e. LW), it means "the last weekday of the month".
-
In the "day of week" field, dL or DDDL stands for "the last day of week d (or DDD) in the month".
-
-
The "day of month" field can be nW, which stands for "the nearest weekday to day of the month n". If n falls on Saturday, this yields the Friday before it. If n falls on Sunday, this yields the Monday after, which also happens if n is 1 and falls on a Saturday (i.e. 1W stands for "the first weekday of the month").
-
The "day of week" field can be d#n (or DDD#n), which stands for "the n-th day of week d (or DDD) in the month".