From d64acc9806e0afd65c251d1b98fa9d4f17250f1e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Sep 2023 14:15:20 +0600 Subject: [PATCH] potential fix of #65 --- CHANGELOG.md | 2 ++ src/commonMain/kotlin/internal/NearDateTimeCalculator.kt | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c19e4e..160e6cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 2.2.1 +* Potential fix of [#65](https://github.com/InsanusMokrassar/krontab/issues/65) + ## 2.2.0 * Versions diff --git a/src/commonMain/kotlin/internal/NearDateTimeCalculator.kt b/src/commonMain/kotlin/internal/NearDateTimeCalculator.kt index 9853bf5..bcc698d 100644 --- a/src/commonMain/kotlin/internal/NearDateTimeCalculator.kt +++ b/src/commonMain/kotlin/internal/NearDateTimeCalculator.kt @@ -108,13 +108,19 @@ internal fun NearDateTimeCalculatorDays( } else { dateTime }) - dateTime.copy( + val newDateTime = dateTime.copy( dayOfMonth = min(dateTime.month.days(dateTime.year), newOne.toInt() + 1), // index1 hour = 0, minute = 0, second = 0, milliseconds = 0 ) + // If day of month has not been changed, use old dateTime due to no changes required + if (newDateTime.dayOfMonth == dateTime.dayOfMonth) { + dateTime + } else { + newDateTime + } } )