I am trying the ECMA-402 International API to get the timezone abbreviation in a timezone that is not the local timezone (server timezone is UTC). I know other ways to get this. I am trying to understand the limitations of and make best use of the International API. I can get the full timezone name and map it myself, but as the abbreviations are in the IANA tz database and the International API is supposed to be based on this, it seems it should be able to produce them, which makes me think I am doing something wrong.
I have the following code:
const fmt = new Intl.DateTimeFormat('en', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: 'numeric',
fractionalSecondDigits: 3,
hour12: false,
weekday: 'short',
timeZoneName: 'short',
timeZone: 'Pacific/Auckland'
});
const now = new Date();
console.log(fmt.format(now));
const fmt2 = new Intl.DateTimeFormat('en', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: 'numeric',
fractionalSecondDigits: 3,
hour12: false,
weekday: 'short',
timeZoneName: 'short',
timeZone: 'America/Los_Angeles'
});
console.log(fmt2.format(now));
In both node 12.16.1 and Firefox 73.0.1 this produces output like the following:
Wed, 04/08/2020, 18:14:50 GMT+12
Tue, 04/07/2020, 23:14:50 PDT
The America/Los_Angeles timezone gets the timezone abbreviation as expected but the Pacific/Auckland timezone does not. The IANA tz database has the abbreviations for Pacific/Auckland and the operating system (Debian Linux) produces them.
Is there anything I can do differently to get the abbreviations from the International API? Or is this simply the state of the art?
I note that both luxon and date-fns-tz depend on the International API and they also fail to produce the abbreviations for Pacific/Auckland.