Skip to content

Commit da1e18d

Browse files
committed
More diagnostic info
1 parent 3eff33a commit da1e18d

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

core/windows/src/internal/TzdbInRegistry.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,16 @@ internal class TzdbInRegistry: TimeZoneDatabase {
6060
}
6161
}
6262
}
63-
val lastOffset = offsets.lastOrNull()
64-
if (lastOffset == null) {
65-
offsets.add(recurring.offsetAtYearStart())
66-
} else {
63+
offsets.lastOrNull()?.let { lastOffset ->
6764
/* If there are already some offsets, we can not add a new offset without defining a transition to
6865
it. The moment when we start using the recurring rules is the first year that does not have any
6966
historic data provided. */
7067
val firstYearWithRecurringRules = historic.last().first + 1
7168
val newYearInLastOffset = LocalDate(firstYearWithRecurringRules, Month.JANUARY, 1).atTime(0, 0)
7269
.toInstant(lastOffset)
7370
transitionEpochSeconds.add(newYearInLastOffset.epochSeconds)
74-
offsets.add(offsets.last())
7571
}
72+
offsets.add(recurring.offsetAtYearStart())
7673
TimeZoneRules(transitionEpochSeconds, offsets, recurringRules)
7774
}
7875
put(name, rules)
@@ -335,7 +332,9 @@ private class PerYearZoneRulesDataWithTransitions(
335332
val standardTransition get() =
336333
RecurringZoneRules.Rule(standardTransitionTime, offsetBefore = daylightOffset, offsetAfter = standardOffset)
337334

338-
override fun offsetAtYearStart(): UtcOffset = standardOffset // TODO: not true in all years + all zones
335+
override fun offsetAtYearStart(): UtcOffset =
336+
if (daylightTransitionTime.toLocalDateTime(2030) < standardTransitionTime.toLocalDateTime(2030))
337+
standardOffset else daylightOffset
339338

340339
override fun toString(): String = "standard offset is $standardOffset" +
341340
", daylight offset is $daylightOffset" +

core/windows/test/TimeZoneRulesCompleteTest.kt

+18-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,24 @@ class TimeZoneRulesCompleteTest {
4242
val ldt = instant.toLocalDateTime(dtzi, inputSystemtime.ptr, outputSystemtime.ptr)
4343
val offset = rules.infoAtInstant(instant)
4444
val ourLdt = instant.toLocalDateTime(offset)
45-
assertEquals(
46-
ldt,
47-
ourLdt,
48-
"in zone $windowsName at $instant (our guess at the offset is $offset). " +
49-
"The rules are $rules"
50-
)
45+
if (ldt != ourLdt) {
46+
val offsetsAccordingToWindows = buildList {
47+
var date = LocalDate(ldt.year, Month.JANUARY, 1)
48+
while (date.year == ldt.year) {
49+
val instant = date.atTime(0, 0).toInstant(UtcOffset.ZERO)
50+
val ldtAccordingToWindows =
51+
instant.toLocalDateTime(dtzi, inputSystemtime.ptr, outputSystemtime.ptr)
52+
val offsetAccordingToWindows = UtcOffset(seconds =
53+
(ldtAccordingToWindows.toInstant(UtcOffset.ZERO) - instant).inWholeSeconds
54+
)
55+
add(instant to offsetAccordingToWindows)
56+
}
57+
}
58+
throw AssertionError(
59+
"Expected $ldt, got $ourLdt in zone $windowsName at $instant (our guess at the offset is $offset)." +
60+
"The rules are $rules, and the offsets throughout the year according to Windows are: "
61+
)
62+
}
5163
}
5264
fun checkTransition(instant: Instant) {
5365
checkAtInstant(instant - 2.milliseconds)

0 commit comments

Comments
 (0)