Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

lalitpagaria/cron-expression-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cron Expression Parser

Introduction

This is java based standard cron expression parser.

Standard

Standard POSIX based cron parser syntax is used.

Implementation

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 -

  1. Handle any value char ?
  2. Allow SUN-SAT representation for day of the week along with 0-6
  3. Allow JAN-DEC representation for month along with 1-12

How to Run

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

About

Parse standard cron expression

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages