Skip to content

Commit c307ad7

Browse files
committed
Tune transition equality
1 parent 647696b commit c307ad7

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,24 @@ function getZoneCfgSinceTime (cutoffTime, cacheFilename) {
148148
Object.keys(zoneCfg).forEach(zone => {
149149
// calculate which offset pattern this zone follows and add it to list
150150
const timezoneInstance = time.Timezone.from(zone)
151-
const currentZoneOffset = timezoneInstance.getOffsetForWallTime(timezoneInstance)
152-
let timekeepingKey = `${currentZoneOffset}`
153-
// Offset-only zones (Etc/UTC, Etc/GMT-3, etc) return null instead of an empty list
154-
const transitions = timezoneInstance.getAllTransitions() || []
151+
const startingZoneOffset = timezoneInstance.getOffsetForWallTime(cutoffTime)
155152

156-
const futureTransitionsHash = hashMd5(transitions.filter(t => t.transitionTime > cutoffTime))
157-
timekeepingKey = `${currentZoneOffset}-${futureTransitionsHash}`
153+
// Offset-only zones (Etc/UTC, Etc/GMT-3, etc) return null instead of an empty list
154+
const transitions = (timezoneInstance.getAllTransitions() || [])
155+
.filter(t => t.transitionTime > cutoffTime)
156+
// Only respect the transition times and total offset for equality. This way, different
157+
// zones that only use different names (like GMT/BST for London but WET/WEST for Lisbon),
158+
// or that mark different periods as standard time (like Dublin which uses +1-1 in the
159+
// winter and +1+0 in summer, whereas London and Lisbon use +0+0 in the winter and +0+1
160+
// in the summer) will still merge.
161+
.map(t => [t.transitionTime, t.utcOffset])
162+
// getAllTransitions returns transitions until March 2499 for Europe/London, but until
163+
// October 2499 for Europe/Dublin, which will lead to a mismatch. This limits the number
164+
// of transitions to something a bit sooner (250 years) so that equality is not impacted
165+
// by this.
166+
.slice(0, 500)
167+
168+
let timekeepingKey = `${startingZoneOffset}-${hashMd5(transitions)}`
158169

159170
if (!timekeepingPatternZones[timekeepingKey]) {
160171
timekeepingPatternZones[timekeepingKey] = []

0 commit comments

Comments
 (0)