romansky / scron   1.1.0

MIT License GitHub

Scala cron parser

Scala versions: 2.13 2.12 2.11 2.10
Scala.js versions: 1.x

scron Build Status

Cron format to time parsing implemented in scala

Usage

import com.uniformlyrandom.scron.Scron

val startTime = DateTime.now.getMillis
val endTime = startTime + ( 60 * 60 )

val times = Scron.parse("* * * * * *", startTime, endTime)
// times is now filled with epoch time for every second for the next hour
times.length == 60 * 60

Supported Cron Formatting

General Format

*	*	*	*	*	*
|	|	|	|	|	|day of week(0-6)
|	|	|	|	|month(1-12)
|	|	|	|day of month(1-31)
|	|	|hour(0-23)
|	|minute(0-59)
|seconds(0-59)

See WikiPedia for more information about the format

Supported Formatting Of Specific Fields

  • * all the options for that field
  • */2 starting from the first option, every other option
  • 0 only use the explicitly provided option
  • 2,4,9 use list of values provided, separated by comma

Installation

Using sbt, add to build.sbt

libraryDependencies ++= Seq(
    	"com.uniformlyrandom" %% "scron" % "1.0.0"
)