From 237b42c2d304c5f1ab402117e91b6968eb75ad65 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 6 Mar 2024 19:36:42 +0600 Subject: [PATCH 1/4] start 2.2.9 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c649cd77..8d879be3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 2.2.9 + ## 2.2.8 * `Version`: diff --git a/gradle.properties b/gradle.properties index f9cc5441..9f5258c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -36,5 +36,5 @@ androidx_work_version=2.9.0 ## Common -version=2.2.8 -android_code_version=38 +version=2.2.9 +android_code_version=39 From af28fce6f548b2b71d80b313e5c50568506d5184 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 6 Mar 2024 20:01:41 +0600 Subject: [PATCH 2/4] update dependencies --- CHANGELOG.md | 4 ++++ gradle.properties | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- src/androidMain/kotlin/KronSchedulerWork.kt | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d879be3..822496ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 2.2.9 +* `Version`: + * `Serialization`: `1.6.3` + * `Klock`: `5.3.2` + ## 2.2.8 * `Version`: diff --git a/gradle.properties b/gradle.properties index 9f5258c2..7d0be6d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,11 +11,11 @@ android.enableJetifier=false kotlin_version=1.9.22 kotlin_coroutines_version=1.8.0 -kotlin_serialization_version=1.6.2 +kotlin_serialization_version=1.6.3 dokka_version=1.9.20 -klockVersion=5.3.1 +klockVersion=5.3.2 ## Github reease diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7b47eff5..e2c62413 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip diff --git a/src/androidMain/kotlin/KronSchedulerWork.kt b/src/androidMain/kotlin/KronSchedulerWork.kt index 09567e94..2f1a3ddf 100644 --- a/src/androidMain/kotlin/KronSchedulerWork.kt +++ b/src/androidMain/kotlin/KronSchedulerWork.kt @@ -139,6 +139,7 @@ abstract class KronSchedulerWork( } throw e } + result.outputData when (result) { is Result.Failure -> if (prolongOnFailure) prolong() is Result.Success -> if (prolongOnSuccess) prolong() From 6845537afd0ca8e3e737fb16087dad6113484225 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 16 Mar 2024 10:31:12 +0600 Subject: [PATCH 3/4] remove redundant change of KronSchedulerWork.kt --- CHANGELOG.md | 1 + gradle.properties | 4 ++-- src/androidMain/kotlin/KronSchedulerWork.kt | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 822496ce..dfba9ba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.2.9 * `Version`: + * `Kotlin`: `1.9.23` * `Serialization`: `1.6.3` * `Klock`: `5.3.2` diff --git a/gradle.properties b/gradle.properties index 7d0be6d5..c6f11125 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,13 +9,13 @@ android.useAndroidX=true android.enableJetifier=false -kotlin_version=1.9.22 +kotlin_version=1.9.23 kotlin_coroutines_version=1.8.0 kotlin_serialization_version=1.6.3 dokka_version=1.9.20 -klockVersion=5.3.2 +klockVersion=5.4.0 ## Github reease diff --git a/src/androidMain/kotlin/KronSchedulerWork.kt b/src/androidMain/kotlin/KronSchedulerWork.kt index 2f1a3ddf..09567e94 100644 --- a/src/androidMain/kotlin/KronSchedulerWork.kt +++ b/src/androidMain/kotlin/KronSchedulerWork.kt @@ -139,7 +139,6 @@ abstract class KronSchedulerWork( } throw e } - result.outputData when (result) { is Result.Failure -> if (prolongOnFailure) prolong() is Result.Success -> if (prolongOnSuccess) prolong() From 2efd7e615768308fa706eb34e87828ba974ab4d5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 16 Mar 2024 15:56:45 +0600 Subject: [PATCH 4/4] fixes in built-in schedulers --- CHANGELOG.md | 1 + src/commonMain/kotlin/SchedulerShortcuts.kt | 35 ++++++++++++++--- .../kotlin/builder/SchedulerBuilder.kt | 29 +++++++++----- src/commonTest/kotlin/BuildersTest.kt | 38 +++++++++++++++++++ 4 files changed, 88 insertions(+), 15 deletions(-) create mode 100644 src/commonTest/kotlin/BuildersTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index dfba9ba0..9638cd89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * `Kotlin`: `1.9.23` * `Serialization`: `1.6.3` * `Klock`: `5.3.2` +* Fixes in build-in schedulers ## 2.2.8 diff --git a/src/commonMain/kotlin/SchedulerShortcuts.kt b/src/commonMain/kotlin/SchedulerShortcuts.kt index ad88b582..7070b9a3 100644 --- a/src/commonMain/kotlin/SchedulerShortcuts.kt +++ b/src/commonMain/kotlin/SchedulerShortcuts.kt @@ -34,35 +34,60 @@ val EverySecondScheduler: KronScheduler by lazy { * [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one minute */ val EveryMinuteScheduler: KronScheduler by lazy { - buildSchedule { minutes { 0 every 1 } } + buildSchedule { + seconds { at(0) } + minutes { 0 every 1 } + } } /** * [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one hour */ val EveryHourScheduler: KronScheduler by lazy { - buildSchedule { hours { 0 every 1 } } + buildSchedule { + seconds { at(0) } + minutes { at(0) } + hours { 0 every 1 } + } } /** * [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one day */ val EveryDayOfMonthScheduler: KronScheduler by lazy { - buildSchedule { dayOfMonth { 0 every 1 } } + buildSchedule { + seconds { at(0) } + minutes { at(0) } + hours { at(0) } + dayOfMonth { 0 every 1 } + } } /** * [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one month */ val EveryMonthScheduler: KronScheduler by lazy { - buildSchedule { months { 0 every 1 } } + buildSchedule { + seconds { at(0) } + minutes { at(0) } + hours { at(0) } + dayOfMonth { at(0) } + months { 0 every 1 } + } } /** * [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one year */ val EveryYearScheduler: KronScheduler by lazy { - buildSchedule { years { 0 every 1 } } + buildSchedule { + seconds { at(0) } + minutes { at(0) } + hours { at(0) } + dayOfMonth { at(0) } + months { at(0) } + years { 0 every 1 } + } } /** diff --git a/src/commonMain/kotlin/builder/SchedulerBuilder.kt b/src/commonMain/kotlin/builder/SchedulerBuilder.kt index 681f2c68..d7d299fb 100644 --- a/src/commonMain/kotlin/builder/SchedulerBuilder.kt +++ b/src/commonMain/kotlin/builder/SchedulerBuilder.kt @@ -182,15 +182,24 @@ class SchedulerBuilder( */ fun build(): KronScheduler = offset ?.let { createKronSchedulerWithOffset( - seconds, - minutes, - hours, - dayOfMonth, - month, - year, - dayOfWeek, - TimezoneOffset(it.minutes), - milliseconds ?: millisecondsArrayDefault + seconds = seconds, + minutes = minutes, + hours = hours, + dayOfMonth = dayOfMonth, + month = month, + years = year, + weekDays = dayOfWeek, + offset = TimezoneOffset(it.minutes), + milliseconds = milliseconds ?: millisecondsArrayDefault ) - } ?: createKronScheduler(seconds, minutes, hours, dayOfMonth, month, year, dayOfWeek, milliseconds ?: millisecondsArrayDefault) + } ?: createKronScheduler( + seconds = seconds, + minutes = minutes, + hours = hours, + dayOfMonth = dayOfMonth, + month = month, + years = year, + weekDays = dayOfWeek, + milliseconds = milliseconds ?: millisecondsArrayDefault + ) } diff --git a/src/commonTest/kotlin/BuildersTest.kt b/src/commonTest/kotlin/BuildersTest.kt new file mode 100644 index 00000000..abb82cd9 --- /dev/null +++ b/src/commonTest/kotlin/BuildersTest.kt @@ -0,0 +1,38 @@ +package dev.inmo.krontab.utils + +import dev.inmo.krontab.* +import korlibs.time.* +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.minutes +import kotlin.time.Duration.Companion.seconds + +class BuildersTest { + @Test + fun presetsWorksCorrectly() { + val data = mapOf( + EverySecondScheduler to { it: DateTime -> if (it.milliseconds > 0 ) it + 1.seconds - it.milliseconds.milliseconds else it }, + EveryMinuteScheduler to { it: DateTime -> if (it.seconds > 0 || it.milliseconds > 0 ) it + 1.minutes - it.seconds.seconds - it.milliseconds.milliseconds else it }, + EveryHourScheduler to { it: DateTime -> if (it.minutes > 0 || it.seconds > 0 || it.milliseconds > 0 ) it + 1.hours - it.minutes.minutes - it.seconds.seconds - it.milliseconds.milliseconds else it }, + EveryDayOfMonthScheduler to { it: DateTime -> if (it.hours > 0 || it.minutes > 0 || it.seconds > 0 || it.milliseconds > 0 ) it + 1.days - it.hours.hours - it.minutes.minutes - it.seconds.seconds - it.milliseconds.milliseconds else it }, + EveryMonthScheduler to { it: DateTime -> if (it.dayOfMonth > 1 || it.hours > 0 || it.minutes > 0 || it.seconds > 0 || it.milliseconds > 0 ) (it + 1.months).copy(dayOfMonth = 1, hour = 0, minute = 0, second = 0, milliseconds = 0) else it }, + ) + val samples = 10000 + + runTest { + var now = DateTime.now() + for (i in 0 until samples) { + data.forEach { (scheduler, expectCalculator) -> + val expectValue = expectCalculator(now) + val newNow = scheduler.nextOrRelative(now) + + assertEquals(expectValue, newNow, "For time ${now.toStringDefault()} calculated wrong value: ${newNow.toStringDefault()} is not equal to ${expectValue.toStringDefault()}") + + now = newNow + } + } + } + } +} \ No newline at end of file