Reputation: 3870
Is the IANA timezone data in nodejs embedded in the Node.js code or does it take the data from the OS?
It seems that it has its own version as process.versions
returns the time zone version as stated here. If so do I need to install a new Node.js version to update the timezone data or is there another way?
Upvotes: 4
Views: 2310
Reputation: 1162
Node.js gets its timezone data from the ICU library, aka International Components for Unicode, which also provides API artefacts to obtain timezone data. Generally, neither Node.js nor the ICU library query external timezone files from the operating system. The ICU library uses its own set of data files including IANA timezone data which is gathered at build time. Note beyond, the tz
property provided by process.versions
refers to timezone data portion as part of the ICU library. I'll get back to this later.
Depending the Node.js distribution you use different build options may apply as described in the Node.js docs, section "Internationalization Support":
"small-icu": The ICU library is bound statically as well as a subset of the ICU data which is compiled into the executable. Apparently "small-icu" is the common build option used for Node.js distributions provided by Nodejs.org (for Linux, at least). However, it is possible to overlay the builtin data with a ICU data archive loaded from file (see docs, section "Providing Icu Data at Runtime"). Various NPM packages exist to download the archive, such as node-icu and full-icu).
"full-icu": Same as "small-icu" but with a full ICU dataset compiled into the executable (which results in a fairly large executable).
"system-icu": The ICU library is bound dynamically with the Node.js executable and needs to be installed as a prerequisite to the Node.js installation. As such the library can be updated independently from node.js installation.
"none": The ICU library is not bound at all. hence there is no timezone data available.
Generally, it should be noted ICU data archive is updated less frequently than the IANA timezone data. Therefore, you may have to deal with outdated timezone information in Node.js even if you always install the latest Node.js LTS release. This is indicated by the tz
properties value 2018e
which indicates a fairly old version of timezone data. The current IANA timezone data is dated from March 2019. For most applications this should be fine, but if you need highest accuracy you need to look for other options:
moment-timezone
or
TimezoneComplete
which included their own compilations of timezone. The
latter seems to be interesting as the
subordinate tzdata
package which contains the timezone dataset is updated
frequently. However, a disadvantage of the library approach is, you're forced
to use a specific API provided by the library rather than "standard"
Javascript/Node.js APIs. This may be problematic in particular if you have a
large codebase to maintain an the code bases on library which handle date/time
objects. Upvotes: 7