From 475c66a469ea4946b4834987d21b64ba51af0eee Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Thu, 9 Jan 2025 14:02:31 +0100 Subject: [PATCH] Attempt to extrapolate the earliest piece of historical data Fixes #440 --- core/windows/src/internal/TzdbInRegistry.kt | 7 +++++-- core/windows/test/TimeZoneRulesCompleteTest.kt | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/windows/src/internal/TzdbInRegistry.kt b/core/windows/src/internal/TzdbInRegistry.kt index f5781da6..7e6f6265 100644 --- a/core/windows/src/internal/TzdbInRegistry.kt +++ b/core/windows/src/internal/TzdbInRegistry.kt @@ -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)] } } diff --git a/core/windows/test/TimeZoneRulesCompleteTest.kt b/core/windows/test/TimeZoneRulesCompleteTest.kt index 038b0ff7..9fda9dd6 100644 --- a/core/windows/test/TimeZoneRulesCompleteTest.kt +++ b/core/windows/test/TimeZoneRulesCompleteTest.kt @@ -95,7 +95,7 @@ class TimeZoneRulesCompleteTest { val firstTransitionYear = Instant.fromEpochSeconds( rules.transitionEpochSeconds.firstOrNull() ?: 0 // arbitrary time ).toLocalDateTime(TimeZone.UTC).year - val yearsToCheck = ((firstTransitionYear - 15).. Boolean): Instant {