This is java based standard cron expression parser.
Standard POSIX based cron parser syntax is used.
Basically each fields of cron expression is parsed individually. For each field there is separate parser class like MinuteFieldParser
, HourFieldParser
etc. All of these classes extends base abstract class FieldParser
. Each fields are parsed by tokenize them based on special chars (allowed chars are *
, /
, ,
and -
).
For each char type special validations checks are performed. For digit in expression, invalid chars, number radix, min and max ranged checks are performed. For step char (/
), number of arguments, divide by zero and negative numbers checks are performed. For asterisk char (*
), multiple occurrence check is performed. And for range char (-
), number range and number of arguments checks are performed. All of these checked are unit tested.
In future following cases can be handled -
- Handle any value char
?
- Allow
SUN-SAT
representation for day of the week along with0-6
- Allow
JAN-DEC
representation for month along with1-12
Install maven 3.x
and JDK 1.8
.
To run unit test cases execute from the project root folder -
mvn clean test
To compile and create jar file execute from the project root folder -
mvn clean package
To execute and parsing cron expression execute from the project root folder -
java -jar target/parser-1.0-SNAPSHOT.jar */15 0 1,15 * 1-5 /usr/bin/find
Note: To handle special char asterisk *
on BASH
, please disable [globbing](https://en.wikipedia.org/wiki/Glob_(programming) using following command -
set -f