Choosing Between Host Timezone Database and Embedded IANA Database for Consistent ClojureScript Date Conversion
0 reputation · 28 Dec 2020, 06:21 UTC
0 reputation · 28 Dec 2020, 06:21 UTC
Goal: achieve portable, timezone‑aware date conversion when compiling ClojureScript to JavaScript targets, so that a date parsed in America/New_York yields the same instant regardless of whether the code runs in a browser, Node.js, or an embedded JS runtime.
Constraint: the built‑in js/Date API relies on the host’s timezone database, which varies across browsers and Node versions, while the cljs‑time wrapper lets developers specify IANA zone strings but requires deciding whether to embed a static IANA bundle or trust the host’s data; additionally, JVM targets can use java.time.ZonedDateTime directly, creating an API gap between platforms.
Uncertainty: choosing between a bundled IANA database (greater consistency but larger bundle and maintenance burden) and the host’s timezone data (smaller footprint but possible offset differences and DST mismatches) remains unresolved, especially when sharing code between JVM and JS builds.
Should we bundle a static IANA database to guarantee uniform offsets across all JS runtimes, or rely on the host’s timezone data and accept potential variation? How does each option affect bundle size, update frequency for DST rules, and runtime performance? What impact does the decision have on sharing timezone‑aware code between JVM and JS targets?
34775 reputation · 28 Dec 2020, 14:32 UTC
When compiling ClojureScript to JavaScript, achieving portable, timezone-aware date conversion requires choosing how zone information is resolved at runtime. The host js/Date API defers to the browser or Node.js timezone database, which varies across versions and builds. The cljs-time wrapper and similar libraries let developers specify IANA zone strings, but must decide between embedding a static IANA bundle or trusting the host data.
Modern mainstream browsers and current Node.js releases ship with the full ICU library, which includes the IANA timezone database. Using Intl.DateTimeFormat with the timeZone option yields consistent offsets for dates near the present, across runs on the same host type. Divergence appears on older runtimes, Node builds compiled with small-icu, or when evaluating dates far in the future or after recent legislative DST changes. Embedding a static IANA database (e.g., via a bundled tzdata package or a library like js-joda with its timezone data) freezes the rule set at build time, guaranteeing identical offsets on any JavaScript runtime, including embedded or exotic environments, but adds tens to hundreds of kilobytes to the bundle and requires redeployment when governments update DST rules.
Does the deployment environment include a Node.js or JavaScript runtime built with small-icu, or is the target exclusively modern browsers and full-ICU Node builds? Answering this will determine whether embedding a static IANA database is necessary or if the host Intl API suffices.
node -e 'console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)'
Confirm the output matches your target zone; repeat on Node builds you suspect may use small-icu.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.