Skip to content

Commit 11c5157

Browse files
authored
Fix the time overlap right boundary being included in the overlap (#404)
Fixes #403 Fixes #399
1 parent f74fdab commit 11c5157

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

core/common/test/TimeZoneTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ private fun checkOverlap(timeZone: TimeZone, overlapStart: LocalDateTime) {
281281
val instantStart = overlapStart.plusNominalSeconds(-1).toInstant(timeZone).plus(1, DateTimeUnit.SECOND)
282282
// the later occurrence of the overlap
283283
val instantEnd = overlapStart.plusNominalSeconds(1).toInstant(timeZone).minus(1, DateTimeUnit.SECOND)
284+
assertEquals(instantEnd, overlapStart.toInstant(timeZone))
284285
try {
285286
// there is at least a one-second overlap
286287
assertNotEquals(instantStart, instantEnd)

core/native/src/internal/TimeZoneRules.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ internal class RecurringZoneRules(
167167
val ldtAfter = rule.transitionDateTime.toLocalDateTime(rule.offsetAfter)
168168
return if (localDateTime < ldtBefore && localDateTime < ldtAfter) {
169169
OffsetInfo.Regular(rule.offsetBefore)
170-
} else if (localDateTime > ldtBefore && localDateTime >= ldtAfter) {
170+
} else if (localDateTime >= ldtBefore && localDateTime >= ldtAfter) {
171171
offset = rule.offsetAfter
172172
continue
173173
} else if (ldtAfter < ldtBefore) {

core/tzfile/test/TimeZoneRulesTest.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ class TimeZoneRulesTest {
2222
// on the last Sunday in October.
2323
val dstStartTime = LocalDateTime(2040, 3, 25, 2, 0)
2424
val infoAtDstStart = rules.infoAtDatetime(dstStartTime)
25-
assertTrue(infoAtDstStart is OffsetInfo.Gap, "Expected Gap, got $infoAtDstStart")
25+
assertIs<OffsetInfo.Gap>(infoAtDstStart)
2626
val dstEndTime = LocalDateTime(2040, 10, 28, 3, 0)
2727
val infoAtDstEnd = rules.infoAtDatetime(dstEndTime)
28-
assertTrue(infoAtDstEnd is OffsetInfo.Overlap, "Expected Overlap, got $infoAtDstEnd")
28+
assertIs<OffsetInfo.Regular>(infoAtDstEnd)
29+
val timeBeforeDstEnd = LocalDateTime(2040, 10, 28, 2, 59, 59, 999_999_999)
30+
val infoBeforeDstEnd = rules.infoAtDatetime(timeBeforeDstEnd)
31+
assertIs<OffsetInfo.Overlap>(infoBeforeDstEnd)
2932
}
3033

3134
@Test

0 commit comments

Comments
 (0)