From af37f4732220d5425914689506a6728a341a9d3b Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 25 Jan 2024 12:03:49 +0100 Subject: [PATCH] Change naming, increase version, update README (#27) --- README.md | 6 ++-- build.gradle.kts | 2 +- .../ucasoft/kcron/core/builders/Builder.kt | 4 +-- .../kcron/core/builders/BuilderTests.kt | 28 +++++++++++++------ 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d54d837..79800fd 100755 --- a/README.md +++ b/README.md @@ -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 @@ -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' } } } @@ -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! diff --git a/build.gradle.kts b/build.gradle.kts index c9cf379..964fd89 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ allprojects { group = "com.ucasoft.kcron" - version = "0.10.0" + version = "0.10.1" repositories { mavenCentral() diff --git a/kcron-core/src/commonMain/kotlin/com/ucasoft/kcron/core/builders/Builder.kt b/kcron-core/src/commonMain/kotlin/com/ucasoft/kcron/core/builders/Builder.kt index 3902bd5..d5757c8 100644 --- a/kcron-core/src/commonMain/kotlin/com/ucasoft/kcron/core/builders/Builder.kt +++ b/kcron-core/src/commonMain/kotlin/com/ucasoft/kcron/core/builders/Builder.kt @@ -78,8 +78,8 @@ class Builder, P: CronDateTimeProvider>(private val } @DelicateIterableApi - fun asIterable(start: T): Iterable { - val internalStart = dateTimeProvider.from(start) + fun asIterable(from: T): Iterable { + val internalStart = dateTimeProvider.from(from) return Iterable { iterator { for (year in (partBuilders.getValue(CronPart.Years) as YearsBuilder<*>).years.filter { y -> y >= internalStart.year }) { diff --git a/kcron-core/src/commonTest/kotlin/com/ucasoft/kcron/core/builders/BuilderTests.kt b/kcron-core/src/commonTest/kotlin/com/ucasoft/kcron/core/builders/BuilderTests.kt index 6f4ddf3..9718c32 100644 --- a/kcron-core/src/commonTest/kotlin/com/ucasoft/kcron/core/builders/BuilderTests.kt +++ b/kcron-core/src/commonTest/kotlin/com/ucasoft/kcron/core/builders/BuilderTests.kt @@ -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 @@ -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) } @@ -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) } @@ -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() } @@ -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) + } }