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
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
Token | Description | Calendar Combination | full # of units |
---|---|---|---|
d | day of year | year , day of year | 5 |
w | week of year | year , week of year , day of week | 6 |
m | special month composed by week | year , month , week of month , day of week | 7 |
c | common mode | year , month , day of month | 6 |
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
mode | Order |
---|---|
d | year day of year hour minute second |
w | year week of year day of week hour minute second |
m | year month week of month day of week hour minute second |
c | year month day of month hour minute second |
Characters
Generally follows conventional character set, see refrences.
Integer
represent date or time, range of available number varies for each unit as following:
Unit | Range | Note |
---|---|---|
year | 1 - 9999 | may be configurable, may vary on implementations |
month | 1 - 12 | |
week of year | 1 - 52 1 - 53 | vary on year |
week of month | 1 - 4 1 - 5 | vary on year and month |
day of year | 1 - 365 , 1 - 366 | vary on leap year |
day of week | 1 - 7 | |
day of month | 1 - 30 1 - 31 1 - 29 1 - 28 | vary on leap year and Feb. |
hour | 0 - 23 | |
minute | 0 - 59 | |
second | 0 - 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
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.
cronx | meaning |
---|---|
* * * * 0..15; d | every minute (of every hour in every day in every year), from 0 second to 15 second |
* 10 1..5 8..10 .. 0; w | from 8:00:00 in 10th Monday to 10:59:00 in 10th Friday in every year |
* 10 1 5 8.. .. ..; m | first Friday in every October, from 8:00:00 to 23:59:59 |
* 10 * 8..10 .. ..; c | every day in every October, from 8:00:00 to 10:59:59 |
This pattern has several rules as following:
- At least one explicit
..
unit pattern should appear; - Only
..
or single number unit pattern should appear after a..
; - If a single number pattern
s
occurs after..
, it will be expanded tos..s
automatically in this context; - You can omit integer on each side of
..
, default are0
andL1
, respectively; i.e.,..
equals0..L1
or1..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
expression | meaning |
---|---|
* 1,L1 8 *; d | every minute of 8 clock in first and last day of every year |
2000 1 1 * */3 0 0; m | every 3 hour of every day in first week of Jan. 2000 |
2000 L1 1,3,5 10 0 0; w | every 10 O'Clock of Monday, Wednesday, Friday in last week of 2000 |
10 10 * *; c | every minute (0 sec) in Oct. 10th, every year |
10 10 * * *; c | every seconds in Oct. 10th, every year |
* * * * 0..15; d | every minute (of every hour in every day in every year), from 0 second to 15 second |
* 10 1..5 8..10 .. 0; w | from 8:00:00 in 10th Monday to 10:59:00 in 10th Friday in every year |
* 10 1 5 8.. .. ..; m | first Friday in every October, from 8:00:00 to 23:59:59 |
* 10 * 8..10 .. ..; c | every day in every October, from 8:00:00 to 10:59:59 |