Skip to content

Commit

Permalink
Simplify lazy initialisation of TimezoneService.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darktrojan committed Apr 3, 2024
1 parent 59245d9 commit ce38022
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions lib/ical/timezone_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,6 +19,10 @@ Object.defineProperties(zones, {
*/
const TimezoneService = {
get count() {
if (zones === null) {
return 0;
}

return Object.keys(zones).length;
},

Expand All @@ -57,6 +42,10 @@ const TimezoneService = {
* @return {Boolean} False, when not present
*/
has: function(tzid) {
if (zones === null) {
return false;
}

return !!zones[tzid];
},

Expand All @@ -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];
},

Expand Down Expand Up @@ -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]);
}
};
Expand Down

0 comments on commit ce38022

Please sign in to comment.