Skip to content

Commit e377868

Browse files
Fix LocalDateTime.nextSecond logic (#130)
Closes #125
1 parent 2faf2dc commit e377868

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/commonMain/kotlin/io/github/kevincianfarini/cardiologist/impl/LocalDateTime.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private fun LocalDateTime.nextSecond(
155155
val incrementedSecond = if (nanosecond > 0) (second + 1) % 60 else second
156156
return when {
157157
incrementedSecond < second -> nextMinute(atMinutes, atHours, onDaysOfMonth, inMonths, increment = true).copy(
158-
second = incrementedSecond
158+
second = minSecond
159159
)
160160
incrementedSecond in atSeconds -> copy(second = incrementedSecond)
161161
incrementedSecond < minSecond -> copy(second = minSecond)

src/commonTest/kotlin/io/github/kevincianfarini/cardiologist/impl/LocalDateTimeTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ class LocalDateTimeTest {
389389
atSeconds(10, 0, 5)
390390
},
391391
)
392+
393+
@Test
394+
fun check_2023_10_04T00_00_59_000000001_next_match_is_correct() = assertEquals(
395+
expected = stubDatetime.copy(minute = 1, second = 1),
396+
actual = stubDatetime.copy(second = 59, nanosecond = 1).nextMatch {
397+
atSeconds(1)
398+
},
399+
)
392400
}
393401

394402
private fun LocalDateTime.assertGap(

0 commit comments

Comments
 (0)