chronos-parser-scala

日本語

A Scala library for parsing and evaluating cron expressions.

CI Scala Steward badge Maven Central Renovate License

Requirements

  • JDK 17 or later (compiled with --release 17)
  • Scala 2.13.18 / 3.3.7 (cross-build supported)

Installation

Add the following to your build.sbt:

libraryDependencies += "com.github.j5ik2o" %% "chronos-parser-scala" % "<version>"

Usage

import com.github.j5ik2o.cron.CronSchedule
import java.time.{Instant, ZoneId}

val cronSchedule = CronSchedule("*/3 * * * *", ZoneId.systemDefault())
val upcoming = cronSchedule.upcoming(Instant.now()).take(5)
upcoming.foreach(println)

API Overview

  • CronSchedule(expr, zoneId) - Create a schedule from a cron expression
  • schedule.upcoming(start) - Get a lazy list of upcoming instants matching the cron expression
  • schedule.getInstantAfter(base, minutes) - Get the next matching instant within a given number of minutes
  • CronParser.parse(expr) - Parse a cron expression into an AST

Supported Cron Syntax

Field Values Special Characters
Minute 0-59 * , - /
Hour 0-23 * , - /
Day of Month 1-31 * , - / L
Month 1-12 * , - /
Day of Week 0-7 (SUN-SAT) * , - /

License

MIT License (see LICENSE)