Skip to content

Commit

Permalink
Change naming, increase version, update README (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scogun authored Jan 25, 2024
1 parent 067a3d8 commit af37f47
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
6 changes: 3 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.0?color=blue)](https://search.maven.org/artifact/com.ucasoft.kcron/kcron-common/0.10.0/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.1?color=blue)](https://search.maven.org/artifact/com.ucasoft.kcron/kcron-common/0.10.1/jar)

### Features
* Kotlin Multiplatform library
Expand Down Expand Up @@ -40,7 +40,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
implementation 'com.ucasoft.kcron:kcron-common:0.10.0'
implementation 'com.ucasoft.kcron:kcron-common:0.10.1'
}
}
}
Expand Down Expand Up @@ -105,6 +105,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.0`.
This library is on beta version `0.10.1`.
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.0"
version = "0.10.1"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class Builder<T, D: CronDateTime<T>, P: CronDateTimeProvider<T, D>>(private val
}

@DelicateIterableApi
fun asIterable(start: T): Iterable<T> {
val internalStart = dateTimeProvider.from(start)
fun asIterable(from: T): Iterable<T> {
val internalStart = dateTimeProvider.from(from)
return Iterable {
iterator {
for (year in (partBuilders.getValue(CronPart.Years) as YearsBuilder<*>).years.filter { y -> y >= internalStart.year }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.collections.shouldBeSingleton
import io.kotest.matchers.collections.shouldHaveElementAt
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.comparables.shouldBeGreaterThan
import io.kotest.matchers.equals.shouldBeEqual
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -144,11 +145,11 @@ class BuilderTests {
// setup cron to run every day at 12:00:00 from 2050 to 2070
val builder = Builder(dateTimeProvider).years(2050..2070).hours(12).minutes(0).seconds(0)
// set start datetime for iterable to 1 Jan 2060 00:00:00
val start = LocalDate(2060, 1, 1).atTime(0, 0, 0)
val from = LocalDate(2060, 1, 1).atTime(0, 0, 0)
// expect first run in 1 Jan 2060 12:00:00
val expected = LocalDate(2060, 1, 1).atTime(12, 0, 0)

val actual = builder.asIterable(start).first()
val actual = builder.asIterable(from).first()
actual.shouldBeEqual(expected)
}

Expand All @@ -157,11 +158,11 @@ class BuilderTests {
// setup cron to run every day at 12:00:00 from 2050 to 2070
val builder = Builder(dateTimeProvider).years(2050..2070).hours(12).minutes(0).seconds(0)
// set start datetime for iterable to 1 Jan 2010 00:00:00
val start = LocalDate(2010, 1, 1).atTime(0, 0, 0)
val from = LocalDate(2010, 1, 1).atTime(0, 0, 0)
// expect first run in 1 Jan 2050 12:00:00 (as defined in cron)
val expected = LocalDate(2050, 1, 1).atTime(12, 0, 0)

val actual = builder.asIterable(start).first()
val actual = builder.asIterable(from).first()
actual.shouldBeEqual(expected)
}

Expand All @@ -170,9 +171,9 @@ class BuilderTests {
// setup cron to run every day at 12:00:00 from 2050 to 2070
val builder = Builder(dateTimeProvider).years(2050..2070).hours(12).minutes(0).seconds(0)
// set start datetime for iterable to 1 Jan 2080 00:00:00
val start = LocalDate(2080, 1, 1).atTime(0, 0, 0)
val from = LocalDate(2080, 1, 1).atTime(0, 0, 0)

val actual = builder.asIterable(start).take(2)
val actual = builder.asIterable(from).take(2)
// expect actual value to be empty because 2080 is out of 2050..2070 range
actual.shouldBeEmpty()
}
Expand All @@ -182,11 +183,22 @@ class BuilderTests {
// setup cron to run every day at 12:00:00 from 2050 to 2070
val builder = Builder(dateTimeProvider).years(2050..2070).hours(12).minutes(0).seconds(0)
// set start datetime for iterable to 1 Jan 2070 00:00:00
val start = LocalDate(2070, 1, 1).atTime(0, 0, 0)
val from = LocalDate(2070, 1, 1).atTime(0, 0, 0)
// set expected runs count to be exactly 365 (once per day)
val expected = 365

val actual = builder.asIterable(start).toList()
val actual = builder.asIterable(from).toList()
actual.shouldHaveSize(expected)
}

@Test
fun iterableShouldStartFromExactProvidedStartDateTime() {
// setup cron to run every day at 00:00:00 from 2050 to 2070
val builder = Builder(dateTimeProvider).years(2050..2070).hours(0).minutes(0).seconds(0)
// set start datetime for iterable to 1 Jan 2050 00:00:00 (exact the same as cron's start)
val from = LocalDate(2050, 1, 1).atTime(0, 0, 0)
// expected iterable's first run will be equal to start
val actual = builder.asIterable(from).first()
actual.shouldBeGreaterThan(from)
}
}

0 comments on commit af37f47

Please sign in to comment.