Skip to content

Commit

Permalink
Add cron functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Scogun committed Feb 2, 2024
1 parent af37f47 commit 430f01f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# KCron
Cron realization for Kotlin Multiplatform

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Scogun_kcron-common&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Scogun_kcron-common) ![GitHub](https://img.shields.io/github/license/Scogun/kcron-common?color=blue) ![Publish workflow](https://github.com/Scogun/kcron-common/actions/workflows/publish.yml/badge.svg) [![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.kcron/kcron-common/0.10.1?color=blue)](https://search.maven.org/artifact/com.ucasoft.kcron/kcron-common/0.10.1/jar)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Scogun_kcron-common&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Scogun_kcron-common) ![GitHub](https://img.shields.io/github/license/Scogun/kcron-common?color=blue) ![Publish workflow](https://github.com/Scogun/kcron-common/actions/workflows/publish.yml/badge.svg) [![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.kcron/kcron-common/0.10.2?color=blue)](https://search.maven.org/artifact/com.ucasoft.kcron/kcron-common/0.10.2/jar)

### Features
* Kotlin Multiplatform library
Expand All @@ -16,6 +16,16 @@ builder
.daysOfWeek(7 on 5) // On the 5th Sunday of the month
.years(2050) // Specific year: 2050
```
* Build Cron expression via Kotlin style function:
```kotlin
cron {
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 Sunday of the month
years(2050) // Specific year: 2050
}
```
* Support custom first week day
```kotlin
val builder = Builder(WeekDays.Sunday)
Expand All @@ -40,7 +50,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
implementation 'com.ucasoft.kcron:kcron-common:0.10.1'
implementation 'com.ucasoft.kcron:kcron-common:0.10.2'
}
}
}
Expand Down Expand Up @@ -105,6 +115,6 @@ builder.years(2021..2025)
println(builder.expression) // 0/10 5-25 5,12 ? * SUN#5 2021-2025
```
### Current status
This library is on beta version `0.10.1`.
This library is on beta version `0.10.2`.
It is continuing to develop.
Check the news!
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ allprojects {

group = "com.ucasoft.kcron"

version = "0.10.1"
version = "0.10.2"

repositories {
mavenCentral()
Expand Down
9 changes: 9 additions & 0 deletions kcron-common/src/commonMain/kotlin/com/ucasoft/kcron/Cron.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.ucasoft.kcron

import com.ucasoft.kcron.core.builders.Builder
import com.ucasoft.kcron.core.common.WeekDays
import com.ucasoft.kcron.core.settings.Settings
import com.ucasoft.kcron.kotlinx.datetime.CronLocalDateTime
import com.ucasoft.kcron.kotlinx.datetime.CronLocalDateTimeProvider
import kotlinx.datetime.LocalDateTime
import com.ucasoft.kcron.core.Cron as CoreCron
import com.ucasoft.kcron.core.cron as Core_cron

object Cron {

Expand All @@ -14,6 +18,11 @@ object Cron {
fun builder(firstDayOfWeek: WeekDays = WeekDays.Monday) = CoreCron.builder(dateTimeProvider, firstDayOfWeek)
}

fun cron(
firstDayOfWeek: WeekDays = WeekDays.Monday,
body: Builder<LocalDateTime, CronLocalDateTime, CronLocalDateTimeProvider>.() -> Unit
) = Core_cron(CronLocalDateTimeProvider(), firstDayOfWeek, body)

@Deprecated(
message = "Class name should not explicitly tell it's written in Kotlin (with starting 'K'). It would be compiled in Java bytecode, Javascript, etc.",
replaceWith = ReplaceWith("Cron")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ object Cron {
return Builder(provider, firstDayOfWeek)
}
}

fun <T, D : CronDateTime<T>, P : CronDateTimeProvider<T, D>> cron(
provider: P,
firstDayOfWeek: WeekDays = WeekDays.Monday,
body: Builder<T, D, P>.() -> Unit
) = Cron.builder(provider, firstDayOfWeek).apply(body)

0 comments on commit 430f01f

Please sign in to comment.