Skip to content

Commit

Permalink
Attempt to extrapolate the earliest piece of historical data
Browse files Browse the repository at this point in the history
Fixes #440
  • Loading branch information
dkhalanskyjb committed Jan 9, 2025
1 parent 1e339e7 commit 475c66a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions core/windows/src/internal/TzdbInRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ private fun HKEYVar.readHistoricDataFromRegistry(
withRegistryKey(tzHKey, "Dynamic DST", { emptyList() }) { dynDstHKey ->
val firstEntry = dwordBuffer.readValue(dynDstHKey, "FirstEntry")
val lastEntry = dwordBuffer.readValue(dynDstHKey, "LastEntry")
(firstEntry..lastEntry).map { year ->
year to zoneRulesBuffer.readZoneRules(dynDstHKey, year.toString())
val registryData = (firstEntry..lastEntry).map { year ->
zoneRulesBuffer.readZoneRules(dynDstHKey, year.toString())
}
(1970..lastEntry).map { year ->
year to registryData[(year - firstEntry).coerceAtLeast(0)]
}
}

Expand Down
9 changes: 7 additions & 2 deletions core/windows/test/TimeZoneRulesCompleteTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TimeZoneRulesCompleteTest {
val firstTransitionYear = Instant.fromEpochSeconds(
rules.transitionEpochSeconds.firstOrNull() ?: 0 // arbitrary time
).toLocalDateTime(TimeZone.UTC).year
val yearsToCheck = ((firstTransitionYear - 15)..<firstTransitionYear) +
val yearsToCheck = (maxOf(firstTransitionYear - 15, 1970)..<firstTransitionYear) +
((lastTransitionYear + 1)..(lastTransitionYear + 15))
for (year in yearsToCheck) {
val rulesForYear = rules.recurringZoneRules!!.rulesForYear(year)
Expand Down Expand Up @@ -184,8 +184,13 @@ private fun SYSTEMTIME.toLocalDateTime(): LocalDateTime =
)

private val strangeTimeZones = listOf(
// These report transitions in the future that are not in the registry:
"Morocco Standard Time", "West Bank Standard Time", "Iran Standard Time", "Syria Standard Time",
"Paraguay Standard Time"
"Paraguay Standard Time",
// This one reports transitions on Jan 1st for years 1970..2003, but the registry contains transitions
// on the first Thursday of January.
// Neither of these is correct: https://en.wikipedia.org/wiki/Daylight_saving_time_in_Brazil
"Central Brazilian Standard Time"
)

private fun binarySearchInstant(instant1: Instant, instant2: Instant, predicate: (Instant) -> Boolean): Instant {
Expand Down

0 comments on commit 475c66a

Please sign in to comment.