public class CronExpression
extends java.lang.Object
Parser for unix-like cron expressions: Cron expressions allow specifying combinations of criteria for time such as: "Each Monday-Friday at 08:00" or "Every last friday of the month at 01:30"
A cron expressions consists of 5 or 6 mandatory fields (seconds may be omitted) separated by space.
These are:
Field | Allowable values | Special Characters | ||
---|---|---|---|---|
Seconds (may be omitted) |
0-59 |
, - * / |
||
Minutes |
0-59 |
, - * / |
||
Hours |
0-23 |
, - * / |
||
Day of month |
1-31 |
, - * ? / L W |
||
Month |
1-12 or JAN-DEC (note: english abbreviations) |
, - * / |
||
Day of week |
1-7 or MON-SUN (note: english abbreviations) |
, - * ? / L # |
‘‘ Can be used in all fields and means ‘for all values’. E.g. "*" in minutes, means ‘for all minutes’ ’?‘ Ca be used in Day-of-month and Day-of-week fields. Used to signify ‘no special value’. It is used when one want to specify something for one of those two fields, but not the other. ’-‘ Used to specify a time interval. E.g. "10-12" in Hours field means ‘for hours 10, 11 and 12’ ’,‘ Used to specify multiple values for a field. E.g. "MON,WED,FRI" in Day-of-week field means "for monday, wednesday and friday" ’/‘ Used to specify increments. E.g. "0/15" in Seconds field means "for seconds 0, 15, 30, ad 45". And "5/15" in seconds field means "for seconds 5, 20, 35, and 50". If ’
‘L’ Can be used on Day-of-month and Day-of-week fields. It signifies last day of the set of allowed values. In Day-of-month field it’s the last day of the month (e.g.. 31 jan, 28 feb (29 in leap years), 31 march, etc.). In Day-of-week field it’s Sunday. If there’s a prefix, this will be subtracted (5L in Day-of-month means 5 days before last day of Month: 26 jan, 23 feb, etc.)
‘W’ Can be specified in Day-of-Month field. It specifies closest weekday (monday-friday). Holidays are not accounted for. "15W" in Day-of-Month field means ‘closest weekday to 15 i in given month’. If the 15th is a Saturday, it gives Friday. If 15th is a Sunday, the it gives following Monday.
‘#’ Can be used in Day-of-Week field. For example: "5#3" means ‘third friday in month’ (day 5 = friday, #3 - the third). If the day does not exist (e.g. "5#5" - 5th friday of month) and there aren’t 5 fridays in the month, then it won’t match until the next month with 5 fridays.
Case-sensitivt No fields are case-sensitive
Dependencies between fields Fields are always evaluated independently, but the expression doesn’t match until the constraints of each field are met.Feltene evalueres Overlap of intervals are not allowed. That is: for Day-of-week field "FRI-MON" is invalid,but "FRI-SUN,MON" is valid
Constructor and Description |
---|
CronExpression(java.lang.String expr) |
CronExpression(java.lang.String expr,
boolean withSeconds) |
Modifier and Type | Method and Description |
---|---|
static CronExpression |
create(java.lang.String expr) |
static CronExpression |
createWithoutSeconds(java.lang.String expr) |
org.joda.time.DateTime |
nextTimeAfter(org.joda.time.DateTime afterTime) |
org.joda.time.DateTime |
nextTimeAfter(org.joda.time.DateTime afterTime,
org.joda.time.DateTime dateTimeBarrier) |
org.joda.time.DateTime |
nextTimeAfter(org.joda.time.DateTime afterTime,
long durationInMillis) |
java.lang.String |
toString() |
public CronExpression(java.lang.String expr)
public CronExpression(java.lang.String expr, boolean withSeconds)
public static CronExpression create(java.lang.String expr)
public static CronExpression createWithoutSeconds(java.lang.String expr)
public org.joda.time.DateTime nextTimeAfter(org.joda.time.DateTime afterTime)
public org.joda.time.DateTime nextTimeAfter(org.joda.time.DateTime afterTime, long durationInMillis)
public org.joda.time.DateTime nextTimeAfter(org.joda.time.DateTime afterTime, org.joda.time.DateTime dateTimeBarrier)
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014–2017 ActFramework. All rights reserved.