Skip to content

Commit

Permalink
Fix the time overlap right boundary being included in the overlap (#404)
Browse files Browse the repository at this point in the history
Fixes #403
Fixes #399
  • Loading branch information
dkhalanskyjb authored Jul 22, 2024
1 parent f74fdab commit 11c5157
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/common/test/TimeZoneTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private fun checkOverlap(timeZone: TimeZone, overlapStart: LocalDateTime) {
val instantStart = overlapStart.plusNominalSeconds(-1).toInstant(timeZone).plus(1, DateTimeUnit.SECOND)
// the later occurrence of the overlap
val instantEnd = overlapStart.plusNominalSeconds(1).toInstant(timeZone).minus(1, DateTimeUnit.SECOND)
assertEquals(instantEnd, overlapStart.toInstant(timeZone))
try {
// there is at least a one-second overlap
assertNotEquals(instantStart, instantEnd)
Expand Down
2 changes: 1 addition & 1 deletion core/native/src/internal/TimeZoneRules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ internal class RecurringZoneRules(
val ldtAfter = rule.transitionDateTime.toLocalDateTime(rule.offsetAfter)
return if (localDateTime < ldtBefore && localDateTime < ldtAfter) {
OffsetInfo.Regular(rule.offsetBefore)
} else if (localDateTime > ldtBefore && localDateTime >= ldtAfter) {
} else if (localDateTime >= ldtBefore && localDateTime >= ldtAfter) {
offset = rule.offsetAfter
continue
} else if (ldtAfter < ldtBefore) {
Expand Down
7 changes: 5 additions & 2 deletions core/tzfile/test/TimeZoneRulesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class TimeZoneRulesTest {
// on the last Sunday in October.
val dstStartTime = LocalDateTime(2040, 3, 25, 2, 0)
val infoAtDstStart = rules.infoAtDatetime(dstStartTime)
assertTrue(infoAtDstStart is OffsetInfo.Gap, "Expected Gap, got $infoAtDstStart")
assertIs<OffsetInfo.Gap>(infoAtDstStart)
val dstEndTime = LocalDateTime(2040, 10, 28, 3, 0)
val infoAtDstEnd = rules.infoAtDatetime(dstEndTime)
assertTrue(infoAtDstEnd is OffsetInfo.Overlap, "Expected Overlap, got $infoAtDstEnd")
assertIs<OffsetInfo.Regular>(infoAtDstEnd)
val timeBeforeDstEnd = LocalDateTime(2040, 10, 28, 2, 59, 59, 999_999_999)
val infoBeforeDstEnd = rules.infoAtDatetime(timeBeforeDstEnd)
assertIs<OffsetInfo.Overlap>(infoBeforeDstEnd)
}

@Test
Expand Down

0 comments on commit 11c5157

Please sign in to comment.