- This is a Java-based project for parsing and working with cron expressions.
- Cron expressions are commonly used to schedule tasks or events to run at specific times and intervals.
- Expand cron expressions into lists of valid values.
- Supports the standard cron expression format with five fields: minute, hour, day of month, month, and day of week.
- Followed, at the end by a command.
- Not handling the special time strings such as "@yearly".
- Tokens are separated by SPACE character.
- Example
*/15 0 1,15 * 1-5 ls
Fields | Allowed Special Characters |
---|---|
Minute | *,/- |
Hour | *,/- |
Day of Month | *,/-? |
Month | *,/- |
Day Of Week | *,/-? |
- Java 17 or higher.
- Gradle
- Download code from drive and unzip
- OS X
brew install openjdk@17
- Linux
sudo apt-get update sudo apt-get install openjdk-17-jdk
- OS X
brew install gradle
- Linux
sudo apt-get update sudo apt-get install gradle
- Move to the project root & run following command
- OS X / Linux
./gradlew jar
- You can locate the generated JAR file in the "build/libs" directory. It will have a name like " your-project-name-version.jar".
Open in the directory where the jar file is present.
java -jar {jarName}.jar "cron_expression"
java -jar cronparser-1.0-SNAPSHOT.jar "*/15 0 1,15 * 1-5 /usr/bin/find"
Required Field : argument (cron_expression), else exception will be thrown.
- Parsing correct cron expression
java -jar cronparser-1.0-SNAPSHOT.jar "*/15 0 1,15 * 1-5 /usr/bin/find"
Output
- Parsing incorrect expression with missing field.
java -jar cronparser-1.0-SNAPSHOT.jar "**"
Output