Skip to content

Fix the time overlap right boundary being included in the overlap #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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