From ce38022c0fdf2b310a1a0127cbd53d58b4cd1267 Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Thu, 4 Apr 2024 12:45:08 +1300 Subject: [PATCH] Simplify lazy initialisation of TimezoneService. It appears the current way of bootstrapping the core zones exists because TimezoneService's position among the modules means we can't call reset immediately. Something seem to not work right and leads to Time.epochTime being in the floating time zone instead of UTC. At least when run in Thunderbird, I'm not sure if it always happens. My patch just creates the zones on first use. --- lib/ical/timezone_service.js | 37 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/ical/timezone_service.js b/lib/ical/timezone_service.js index 3574a693..ceabc46f 100644 --- a/lib/ical/timezone_service.js +++ b/lib/ical/timezone_service.js @@ -6,26 +6,7 @@ import Timezone from "./timezone.js"; import Component from "./component.js"; -let zones = { -}; - -function lazyZone(name) { - return { - configurable: true, - enumerable: true, - get: function() { - delete this[name]; - TimezoneService.reset(); - return this[name]; - } - }; -} - -Object.defineProperties(zones, { - Z: lazyZone("Z"), - UTC: lazyZone("UTC"), - GMT: lazyZone("GMT"), -}); +let zones = null; /** * @classdesc @@ -38,6 +19,10 @@ Object.defineProperties(zones, { */ const TimezoneService = { get count() { + if (zones === null) { + return 0; + } + return Object.keys(zones).length; }, @@ -57,6 +42,10 @@ const TimezoneService = { * @return {Boolean} False, when not present */ has: function(tzid) { + if (zones === null) { + return false; + } + return !!zones[tzid]; }, @@ -67,6 +56,10 @@ const TimezoneService = { * @return {?ICAL.Timezone} The timezone, or null if not found */ get: function(tzid) { + if (zones === null) { + this.reset(); + } + return zones[tzid]; }, @@ -101,6 +94,10 @@ const TimezoneService = { * @return {?ICAL.Timezone} The removed timezone, or null if not registered */ remove: function(tzid) { + if (zones === null) { + return null; + } + return (delete zones[tzid]); } };