Skip to main content

Details

cronx is an expression to describe various date and time patterns using a set of characters, it extends the conventional cron expression and provides more expressive power over time patterns;

Each expression consists of several time units, order from year to second, left to right; and each unit consist of a character set; It also requires a calendar mode indicator at the end, with a ; seperator between the main expression and mode indicator;

Time Unit

year, month, week of year, week of month, day of year, day of week, day of month, hour, minute, second

info

All week date definition follows ISO standard, see details

Quick Explainations:

  • week 01 in year is the week with the first Thursday of the Gregorian year (i.e. of January) in it.

  • weeks in month: not explicitly defined by ISO standard but the rule for first week of the year might be applied.

    In this case The first day of the month is one of the following:

    • Thursday and the month has 29 through 31 days.
    • Wednesday and the month has 30 or 31 days.
    • Tuesday and the month has 31 days, ending on a Thursday.

Calendar Mode and Indicator

full # of units include three clock units: hour, minute, second

TokenDescriptionCalendar Combinationfull # of units
dday of yearyear, day of year5
wweek of yearyear, week of year, day of week6
mspecial month composed by weekyear, month, week of month, day of week7
ccommon modeyear, month, day of month6
info

All indicator tokens should be at the end of an expression, and using ; to seperate from the main expression.

Order of Units

Generally, cronx takes a reverse order compared to cron, that is from bigger unit to smaller one

modeOrder
dyear day of year hour minute second
wyear week of year day of week hour minute second
myear month week of month day of week hour minute second
cyear month day of month hour minute second

Characters

info

Generally follows conventional character set, see refrences.

Integer

represent date or time, range of available number varies for each unit as following:

UnitRangeNote
year1 - 9999may be configurable, may vary on implementations
month1 - 12
week of year1 - 52 1 - 53vary on year
week of month1 - 4 1 - 5vary on year and month
day of year1 - 365, 1 - 366vary on leap year
day of week1 - 7
day of month1 - 30 1 - 31 1 - 29 1 - 28vary on leap year and Feb.
hour0 - 23
minute0 - 59
second0 - 59

Asterisk *

a wildcard represents "all". For example, * * * * *; d represent every second in day of year mode;

Comma ,

Commas are used to separate items of a list. For example, 1,3,5 on day of week position means Monday, Wednesday and Friday;

Hyphen -

Hyphen defines ranges. For example, "2000-2010" indicates every year between 2000 and 2010, inclusive.

Slash /

slashes can be combined with ranges to specify step values. For example, */10 in the minutes field indicates every 10 minutes, and semantic equivalent to 0,10, 20, 30, 40, 50

note

When use forms like a-b/c, you may encouter with a situation that b does not comply with the sequence which a and c define; in this context, the last number a-b/c represents is max(a+c*i) where i > 0 and i is integer;

i.e. 1-9/5 represents 1, 6

Letter L

L stands for "last". It is a useful indicator to represent ordinal in reverse order. Since correct pattern range is essential for correct and fast computation, explicity is much desired; It is highly recommended to use L indicator when you need to represent numbers close to end of a unit range, especially for calendar units that the range could vary on different circumstances;

Two Dots ..

Special Characters for time span representation, see detail in time span section;

Span of Time

This is a new concept, it represents a span or a block of time from a start to an end expressed by cronx, start and end occur in pairs, and connected by new character set .. in cronx.

cronxmeaning
* * * * 0..15; devery minute (of every hour in every day in every year), from 0 second to 15 second
* 10 1..5 8..10 .. 0; wfrom 8:00:00 in 10th Monday to 10:59:00 in 10th Friday in every year
* 10 1 5 8.. .. ..; mfirst Friday in every October, from 8:00:00 to 23:59:59
* 10 * 8..10 .. ..; cevery day in every October, from 8:00:00 to 10:59:59

This pattern has several rules as following:

  1. At least one explicit .. unit pattern should appear;
  2. Only .. or single number unit pattern should appear after a ..;
  3. If a single number pattern s occurs after .., it will be expanded to s..s automatically in this context;
  4. You can omit integer on each side of .., default are 0 and L1, respectively; i.e., .. equals 0..L1 or 1..L1;

L1 means the last one;

Length, Omission, and Default

Second and year is not required, and to indicate year, second must be explicit first;

If U is the full number of units for each mode (see table), U - 1 means year is implicit, U - 2 means year and second are implicit.

year is always default to *;

second is default 0 in normal context, and 0..59 in span context;

Examples

expressionmeaning
* 1,L1 8 *; devery minute of 8 clock in first and last day of every year
2000 1 1 * */3 0 0; mevery 3 hour of every day in first week of Jan. 2000
2000 L1 1,3,5 10 0 0; wevery 10 O'Clock of Monday, Wednesday, Friday in last week of 2000
10 10 * *; cevery minute (0 sec) in Oct. 10th, every year
10 10 * * *; cevery seconds in Oct. 10th, every year
* * * * 0..15; devery minute (of every hour in every day in every year), from 0 second to 15 second
* 10 1..5 8..10 .. 0; wfrom 8:00:00 in 10th Monday to 10:59:00 in 10th Friday in every year
* 10 1 5 8.. .. ..; mfirst Friday in every October, from 8:00:00 to 23:59:59
* 10 * 8..10 .. ..; cevery day in every October, from 8:00:00 to 10:59:59