moment / moment-timezone

Timezone support for moment.js
momentjs.com/timezone
MIT License
3.83k stars 838 forks source link

Format issue: wrong timezone name #1117

Open AlimovSV opened 1 month ago

AlimovSV commented 1 month ago

Environment

{
  moment: '2.30.1',
  momentTz: '0.5.45',
  date: 'Fri Sep 20 2024 15:50:16 GMT+0400 (Самарское стандартное время)',
  intlZone: 'Europe/Samara'
}

Issue description

>  moment.updateLocale('en-au')
...
>  moment('2023-04-17T20:47:08.962599+08:45').tz('Australia/Eucla').format('lll z')
'Apr 17, 2023 8:47 PM +0845'

formatted zone name is +0845 but expected ACWST

> Intl.DateTimeFormat("en-AU", {
...   timeZone: "Australia/Eucla",
...   day: "numeric",
...   month: "short",
...   year: "numeric",
...   hour: "numeric",
...   minute: "numeric",
...   timeZoneName: "short"
... }).format(new Date('2023-04-17T20:47:08.962599+08:45'))
'17 Apr 2023, 8:47 pm ACWST'

Looks like the problem is in the timezone definitions:

{
  name: 'Australia/Eucla',
  abbrs: [
    'LMT',   '+0845', '+0945',
    '+0845', '+0945', '+0845',
    '+0945', '+0845', '+0945',
    '+0845', '+0945', '+0845',
    '+0945', '+0845', '+0945',
    '+0845', '+0945', '+0845',
    '+0945', '+0845'
  ],
  untils: [
    -2337928528000, -1672555500000,
    -1665384300000,  -883637100000,
     -876120300000,  -860395500000,
     -844670700000,   152039700000,
      162926100000,   436295700000,
      447182100000,   690311700000,
      699383700000,  1165079700000,
     1174756500000,  1193505300000,
     1206810900000,  1224954900000,
     1238260500000,       Infinity
  ],
  offsets: [
    -515.4666666666667, -525,
                  -585, -525,
                  -585, -525,
                  -585, -525,
                  -585, -525,
                  -585, -525,
                  -585, -525,
                  -585, -525,
                  -585, -525,
                  -585, -525
  ],
  population: 368
}
sslincoco commented 1 month ago

您的邮件已收到,我会尽快给您回复。

gilmoreorless commented 1 month ago

The abbreviation "ACWST" was originally invented by the lead maintainer of the time zone database, and is not actually the real designation of the zone. The Australia/Eucla zone is for a region that isn't officially recognised by the government as having a separate time zone (it's just a bunch of local towns that change their clocks voluntarily), so there isn't any real abbreviation for the zone.

A few years ago, the tzdb maintainers started removing these previously made-up names and replacing them with plain offsets. The change to Australia/Eucla was done in 2017 (https://github.com/eggert/tz/commit/a25d615495c57081297939b4befe6f9b6bf438ea) and has been in the Moment Timezone data ever since.

Some browsers have chosen to continue using the deprecated, unofficial names for backwards compatibility. That explains why you still see "ACWST" in the Intl.DateTimeFormat result.

I'm going to keep this issue open, as a reminder to add some documentation about these cases. This isn't the first time that users have been confused by the offsets appearing as zone names.