KCron Common

Cron realization for Kotlin Multiplatform

License

License

Categories

Categories

Data
GroupId

GroupId

com.ucasoft.kcron
ArtifactId

ArtifactId

kcron-common-metadata
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

KCron Common
Cron realization for Kotlin Multiplatform
Project URL

Project URL

https://github.com/Scogun/kcron-common
Source Code Management

Source Code Management

https://github.com/Scogun/kcron-common

Download kcron-common-metadata

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.4.10

Project Modules

There are no modules declared in this project.

KCron Common

Cron realization for Kotlin Multiplatform

Maven Central with version prefix filter

Features

  • Kotlin Multiplatform library
  • Parse Cron expressions
    • Include L, W, LW, '?' and #
  • Build Cron expression by smart builder functions:
builder
    .seconds(10 at 0) //Every 10 seconds starting at 0 seconds
    .minutes(5..25) // Every minute between 5 and 25
    .hours(5, 12) // Specific hours: 5 and 12
    .daysOfWeek(7 on 5) // On the 5th Saturday of the month
    .years(2050) // Specific year: 2050
  • Parsing validation includes combination rules
    • 'days' and 'days of week' could not be setup simultaneously

Usage

Add with Gradle

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                implementation 'com.ucasoft.kcron:kcron-common:0.2.0'
            }
        }
    }
}

Build Cron expression

val builder = KCron.builder()
// By default builder contains any expression for every part
println(builder.expression) // * * * ? * * *
builder
    .seconds(10 at 0)
    .minutes(5..25)
    .hours(5, 12)
    .daysOfWeek(7 on 5)
    .years(2050)
println(builder.expression) // 0/10 5-25 5,12 ? * 7#5 2050

Parse Cron expression

val builder = KCron.parseAndBuild("0/10 5-25 5,12 ? * 7#5 2050")
println(builder.nextRunList()) // 10 is a default list size
/* Result:
[
    2050-01-29T05:05,
    2050-01-29T05:05:10,
    2050-01-29T05:05:20,
    2050-01-29T05:05:30,
    2050-01-29T05:05:40,
    2050-01-29T05:05:50,
    2050-01-29T05:06,
    2050-01-29T05:06:10,
    2050-01-29T05:06:20,
    2050-01-29T05:06:30
]
*/ 

Days of week and months can be defined in a parsed expression as numbers as well as short names

builder = KCron.parseAndBuild("15/10 5-25 5 ? JAN,MAR 2,3,4,5 2050")
println(builder.nextRun) // 2050-01-03T05:05:15
// OR
builder = KCron.parseAndBuild("15/10 5-25 5 ? 2-4 MON 2050")
println(builder.nextRun) // 2050-02-07T05:05:15

Easy change any part of expression

val builder = KCron.parseAndBuild("0/10 5-25 5,12 ? * 7#5 2050")
builder.years(2021..2025)
println(builder.expression) // 0/10 5-25 5,12 ? * 7#5 2021-2025

Current status

This library is on alpha version 0.2.0. However, it will be a part of another cool library. Check the news!

Versions

Version
0.2.0
0.1.5
0.1.4