From f163a64964b7b3498975c05f8d6b6278d6c6a393 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 14 Jun 2022 00:14:15 +0600 Subject: [PATCH 1/8] start 0.7.3 --- gradle.properties | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5eb2793..9c92126 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,10 +8,10 @@ android.useAndroidX=true android.enableJetifier=false -kotlin_version=1.6.10 +kotlin_version=1.6.21 kotlin_coroutines_version=1.6.1 -dokka_version=1.6.10 +dokka_version=1.6.21 klockVersion=2.7.0 @@ -33,5 +33,5 @@ androidx_work_version=2.7.1 ## Common -version=0.7.2 -android_code_version=13 +version=0.7.3 +android_code_version=14 From 58f30aef1526b41b90506e0e875e24ce63120477 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Jun 2022 12:40:03 +0600 Subject: [PATCH 2/8] fix of #27 --- .../kotlin/dev/inmo/krontab/StringParser.kt | 14 +++++++------- .../dev/inmo/krontab/internal/CronDateTime.kt | 2 +- .../krontab/internal/NearDateTimeCalculator.kt | 7 ++++--- .../inmo/krontab/utils/InfinityLoopCheckTest.kt | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt diff --git a/src/commonMain/kotlin/dev/inmo/krontab/StringParser.kt b/src/commonMain/kotlin/dev/inmo/krontab/StringParser.kt index 9e1e6da..1a3b1e2 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/StringParser.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/StringParser.kt @@ -57,13 +57,13 @@ typealias KrontabTemplate = String * * "0/5,L * * * *" for every five seconds triggering and on 59 second * * "0/15 30 * * *" for every 15th seconds in a half of each hour * * "0/15 30 * * * 500ms" for every 15th seconds in a half of each hour when milliseconds equal to 500 - * * "1 2 3 F,4,L 5" for triggering in near first second of second minute of third hour of fourth day of may - * * "1 2 3 F,4,L 5 60o" for triggering in near first second of second minute of third hour of fourth day of may with timezone UTC+01:00 - * * "1 2 3 F,4,L 5 60o 0-2w" for triggering in near first second of second minute of third hour of fourth day of may in case if it will be in Sunday-Tuesday week days with timezone UTC+01:00 - * * "1 2 3 F,4,L 5 2021" for triggering in near first second of second minute of third hour of fourth day of may of 2021st year - * * "1 2 3 F,4,L 5 2021 60o" for triggering in near first second of second minute of third hour of fourth day of may of 2021st year with timezone UTC+01:00 - * * "1 2 3 F,4,L 5 2021 60o 0-2w" for triggering in near first second of second minute of third hour of fourth day of may of 2021st year if it will be in Sunday-Tuesday week days with timezone UTC+01:00 - * * "1 2 3 F,4,L 5 2021 60o 0-2w 500ms" for triggering in near first second of second minute of third hour of fourth day of may of 2021st year if it will be in Sunday-Tuesday week days with timezone UTC+01:00 when milliseconds will be equal to 500 + * * "1 2 3 F,4,L 5" for triggering in near first second of second minute of third hour of first, fifth and last days of may + * * "1 2 3 F,4,L 5 60o" for triggering in near first second of second minute of third hour of first, fifth and last days of may with timezone UTC+01:00 + * * "1 2 3 F,4,L 5 60o 0-2w" for triggering in near first second of second minute of third hour of first, fifth and last days of may in case if it will be in Sunday-Tuesday week days with timezone UTC+01:00 + * * "1 2 3 F,4,L 5 2021" for triggering in near first second of second minute of third hour of first, fifth and last days of may of 2021st year + * * "1 2 3 F,4,L 5 2021 60o" for triggering in near first second of second minute of third hour of first, fifth and last days of may of 2021st year with timezone UTC+01:00 + * * "1 2 3 F,4,L 5 2021 60o 0-2w" for triggering in near first second of second minute of third hour of first, fifth and last days of may of 2021st year if it will be in Sunday-Tuesday week days with timezone UTC+01:00 + * * "1 2 3 F,4,L 5 2021 60o 0-2w 500ms" for triggering in near first second of second minute of third hour of first, fifth and last days of may of 2021st year if it will be in Sunday-Tuesday week days with timezone UTC+01:00 when milliseconds will be equal to 500 * * @return In case when offset parameter is absent in [incoming] will be used [createSimpleScheduler] method and * returned [CronDateTimeScheduler]. In case when offset parameter there is in [incoming] [KrontabTemplate] will be used diff --git a/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTime.kt b/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTime.kt index 729a784..a27e330 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTime.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/internal/CronDateTime.kt @@ -8,7 +8,7 @@ import dev.inmo.krontab.KronScheduler * @param daysOfWeek 0-6 * @param years any int * @param months 0-11 - * @param daysOfMonth 0-31 + * @param daysOfMonth 0-30 * @param hours 0-23 * @param minutes 0-59 * @param seconds 0-59 diff --git a/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt b/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt index 714a3f6..a6ada42 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt @@ -103,12 +103,13 @@ internal fun NearDateTimeCalculatorDays( times, { it.dayOfMonth.toByte() }, { dateTime, newOne -> - (if (newOne < dateTime.dayOfMonth) { + val dateTime = (if (newOne < dateTime.dayOfMonth) { dateTime.plus(1.months) } else { dateTime - }).copy( - dayOfMonth = min(dateTime.month.days(dateTime.year), newOne.toInt() + 1), // index1 + }) + dateTime.copy( + dayOfMonth = min(dateTime.month.days(dateTime.year) - 1, newOne.toInt()), // index1 hour = 0, minute = 0, second = 0, diff --git a/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt b/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt new file mode 100644 index 0000000..8e4cd60 --- /dev/null +++ b/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt @@ -0,0 +1,14 @@ +package dev.inmo.krontab.utils + +import dev.inmo.krontab.buildSchedule +import kotlin.test.Test +import kotlin.test.assertNotNull + +class InfinityLoopCheckTest { + @Test + fun absenceOfInfinityLoopCheckTest() { + runTest { + assertNotNull(buildSchedule("0 0 0 1 *").next()) + } + } +} From 8ac6cd3e627257b063c031d690783bc87fb62372 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Jun 2022 13:27:21 +0600 Subject: [PATCH 3/8] fix of #34 and upfix for #27 --- .../krontab/internal/NearDateTimeCalculator.kt | 6 +++--- .../inmo/krontab/utils/InfinityLoopCheckTest.kt | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt b/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt index a6ada42..7be2050 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt @@ -101,7 +101,7 @@ internal fun NearDateTimeCalculatorDays( times: Array ) = CommonNearDateTimeCalculator( times, - { it.dayOfMonth.toByte() }, + { (it.dayOfMonth - 1).toByte() }, { dateTime, newOne -> val dateTime = (if (newOne < dateTime.dayOfMonth) { dateTime.plus(1.months) @@ -109,7 +109,7 @@ internal fun NearDateTimeCalculatorDays( dateTime }) dateTime.copy( - dayOfMonth = min(dateTime.month.days(dateTime.year) - 1, newOne.toInt()), // index1 + dayOfMonth = min(dateTime.month.days(dateTime.year), newOne.toInt() + 1), // index1 hour = 0, minute = 0, second = 0, @@ -122,7 +122,7 @@ internal fun NearDateTimeCalculatorMonths( times: Array ) = CommonNearDateTimeCalculator( times, - { it.dayOfMonth.toByte() }, + { it.month0.toByte() }, { dateTime, newOne -> (if (newOne < dateTime.month0) { dateTime.plus(1.years) diff --git a/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt b/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt index 8e4cd60..a525ace 100644 --- a/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt +++ b/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt @@ -1,14 +1,22 @@ package dev.inmo.krontab.utils +import com.soywiz.klock.DateTime +import com.soywiz.klock.days import dev.inmo.krontab.buildSchedule -import kotlin.test.Test -import kotlin.test.assertNotNull +import kotlin.test.* class InfinityLoopCheckTest { @Test fun absenceOfInfinityLoopCheckTest() { - runTest { - assertNotNull(buildSchedule("0 0 0 1 *").next()) + val now = DateTime.now().startOfYear.startOfDay + for (i in 0 until now.year.days) { + val scheduleDateTime = (now + i.days) + runTest { + assertEquals( + scheduleDateTime, + buildSchedule("0 0 0 ${scheduleDateTime.dayOfMonth - 1} ${scheduleDateTime.month0}").next(now) + ) + } } } } From 2abef5833592ff62e663a01d502edfe581745433 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Jun 2022 13:31:26 +0600 Subject: [PATCH 4/8] fix of #35 --- .../kotlin/dev/inmo/krontab/LambdaKronScheduler.kt | 13 +++++++++++++ .../dev/inmo/krontab/LambdaKronSchedulerTz.kt | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/commonMain/kotlin/dev/inmo/krontab/LambdaKronScheduler.kt create mode 100644 src/commonMain/kotlin/dev/inmo/krontab/LambdaKronSchedulerTz.kt diff --git a/src/commonMain/kotlin/dev/inmo/krontab/LambdaKronScheduler.kt b/src/commonMain/kotlin/dev/inmo/krontab/LambdaKronScheduler.kt new file mode 100644 index 0000000..5bef0a6 --- /dev/null +++ b/src/commonMain/kotlin/dev/inmo/krontab/LambdaKronScheduler.kt @@ -0,0 +1,13 @@ +package dev.inmo.krontab + +import com.soywiz.klock.DateTime + +class LambdaKronScheduler( + private val onNext: suspend (DateTime) -> DateTime? +) : KronScheduler { + override suspend fun next(relatively: DateTime): DateTime? = onNext(relatively) +} + +fun KronScheduler( + onNext: suspend (DateTime) -> DateTime? +) = LambdaKronScheduler(onNext) diff --git a/src/commonMain/kotlin/dev/inmo/krontab/LambdaKronSchedulerTz.kt b/src/commonMain/kotlin/dev/inmo/krontab/LambdaKronSchedulerTz.kt new file mode 100644 index 0000000..35327ed --- /dev/null +++ b/src/commonMain/kotlin/dev/inmo/krontab/LambdaKronSchedulerTz.kt @@ -0,0 +1,13 @@ +package dev.inmo.krontab + +import com.soywiz.klock.DateTimeTz + +class LambdaKronSchedulerTz( + private val onNext: suspend (DateTimeTz) -> DateTimeTz? +) : KronSchedulerTz { + override suspend fun next(relatively: DateTimeTz): DateTimeTz? = onNext(relatively) +} + +fun KronSchedulerTz( + onNext: suspend (DateTimeTz) -> DateTimeTz? +) = LambdaKronSchedulerTz(onNext) From 0c37ccc902ceccfdd06e09b4c029a99d83c873bb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Jun 2022 13:37:48 +0600 Subject: [PATCH 5/8] fix of #33 --- .../flows/{Filters.kt => DateTimeFilters.kt} | 0 .../krontab/utils/flows/DateTimeTzFilters.kt | 34 +++++++++++++++++++ .../flows/{When.kt => DateTimeTzWhen.kt} | 0 .../inmo/krontab/utils/flows/DateTimeWhen.kt | 25 ++++++++++++++ 4 files changed, 59 insertions(+) rename src/commonMain/kotlin/dev/inmo/krontab/utils/flows/{Filters.kt => DateTimeFilters.kt} (100%) create mode 100644 src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeTzFilters.kt rename src/commonMain/kotlin/dev/inmo/krontab/utils/flows/{When.kt => DateTimeTzWhen.kt} (100%) create mode 100644 src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeWhen.kt diff --git a/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/Filters.kt b/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeFilters.kt similarity index 100% rename from src/commonMain/kotlin/dev/inmo/krontab/utils/flows/Filters.kt rename to src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeFilters.kt diff --git a/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeTzFilters.kt b/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeTzFilters.kt new file mode 100644 index 0000000..e259ca0 --- /dev/null +++ b/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeTzFilters.kt @@ -0,0 +1,34 @@ +package dev.inmo.krontab.utils.flows + +import com.soywiz.klock.* +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.filter + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterSeconds(vararg seconds: Int) = filter { it.seconds in seconds } + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterMinutes(vararg minutes: Int) = filter { it.minutes in minutes } + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterHours(vararg hours: Int) = filter { it.hours in hours } + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterDaysOfMonths(vararg daysOfMonths: Int) = filter { it.dayOfMonth in daysOfMonths } + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterMonths(vararg months: Month) = filter { it.month in months } +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterMonths0(vararg months: Int) = filter { it.month0 in months } +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterMonths1(vararg months: Int) = filter { it.month1 in months } + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterYears(year: Year) = filter { it.year == year } +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterYears(vararg years: Int) = filter { it.yearInt in years } + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterWeekDays(vararg weekDays: DayOfWeek) = filter { it.dayOfWeek in weekDays } +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.filterWeekDays(vararg weekDays: Int) = filter { it.dayOfWeekInt in weekDays } diff --git a/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/When.kt b/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeTzWhen.kt similarity index 100% rename from src/commonMain/kotlin/dev/inmo/krontab/utils/flows/When.kt rename to src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeTzWhen.kt diff --git a/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeWhen.kt b/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeWhen.kt new file mode 100644 index 0000000..9867254 --- /dev/null +++ b/src/commonMain/kotlin/dev/inmo/krontab/utils/flows/DateTimeWhen.kt @@ -0,0 +1,25 @@ +package dev.inmo.krontab.utils.flows + +import com.soywiz.klock.* +import kotlinx.coroutines.flow.Flow + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.onlyStartsOfMinutes() = filterSeconds(0) + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.onlyStartsOfHours() = filterMinutes(0).onlyStartsOfMinutes() + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.onlyStartsOfDays() = filterHours(0).onlyStartsOfHours() + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.onlyStartsOfMondays() = filterWeekDays(DayOfWeek.Monday).onlyStartsOfDays() + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.onlyStartsOfSundays() = filterWeekDays(DayOfWeek.Sunday).onlyStartsOfDays() + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.onlyStartsOfMonths() = filterDaysOfMonths(1).onlyStartsOfDays() + +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.onlyStartsOfYears() = filterMonths(Month.January).onlyStartsOfMonths() From 9ea8194d7d03de513da40102d85b96d4083be6bb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Jun 2022 13:46:37 +0600 Subject: [PATCH 6/8] fill changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08ceae5..ed65b2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.7.3 + +* Versions + * `Kotlin`: `1.6.21` +* Several bug fixes ([#27](https://github.com/InsanusMokrassar/krontab/issues/27), [#34](https://github.com/InsanusMokrassar/krontab/issues/34)) +* New factories for `KronScheduler` and `KronSchedulerTz` (fix of [#35](https://github.com/InsanusMokrassar/krontab/issues/35)) +* Fill extensions for flow with time zones (fix of [#33](https://github.com/InsanusMokrassar/krontab/issues/33)) + ## 0.7.2 * Versions From f63ed1a873541dbc59e2b0fba782895632ba1c3c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Jun 2022 14:43:28 +0600 Subject: [PATCH 7/8] rename check infinity loop test class and fun --- ...inityLoopCheckTest.kt => CheckMonthsAndDaysCorrectWork.kt} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/commonTest/kotlin/dev/inmo/krontab/utils/{InfinityLoopCheckTest.kt => CheckMonthsAndDaysCorrectWork.kt} (87%) diff --git a/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt b/src/commonTest/kotlin/dev/inmo/krontab/utils/CheckMonthsAndDaysCorrectWork.kt similarity index 87% rename from src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt rename to src/commonTest/kotlin/dev/inmo/krontab/utils/CheckMonthsAndDaysCorrectWork.kt index a525ace..60c7d03 100644 --- a/src/commonTest/kotlin/dev/inmo/krontab/utils/InfinityLoopCheckTest.kt +++ b/src/commonTest/kotlin/dev/inmo/krontab/utils/CheckMonthsAndDaysCorrectWork.kt @@ -5,9 +5,9 @@ import com.soywiz.klock.days import dev.inmo.krontab.buildSchedule import kotlin.test.* -class InfinityLoopCheckTest { +class CheckMonthsAndDaysCorrectWork { @Test - fun absenceOfInfinityLoopCheckTest() { + fun checkMonthsAndDaysCorrectWork() { val now = DateTime.now().startOfYear.startOfDay for (i in 0 until now.year.days) { val scheduleDateTime = (now + i.days) From 681043db5a015b523860f762c7887018d27d067e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Jun 2022 14:46:12 +0600 Subject: [PATCH 8/8] Update NearDateTimeCalculator.kt --- .../kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt b/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt index 7be2050..2e3576b 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/internal/NearDateTimeCalculator.kt @@ -101,7 +101,7 @@ internal fun NearDateTimeCalculatorDays( times: Array ) = CommonNearDateTimeCalculator( times, - { (it.dayOfMonth - 1).toByte() }, + { (it.dayOfMonth - 1).toByte() }, // index1, so, decrease { dateTime, newOne -> val dateTime = (if (newOne < dateTime.dayOfMonth) { dateTime.plus(1.months)