My system time zone is America/Los_Angeles, where the start of daylight saving time on 2023-03-12 jumped the local time directly from 01:59 (-08:00) to 03:00 (-07:00). The UTC time zone had no such jump, of course, so one wouldn’t expect any issues formatting a UTC date between 01:59 (Z) and 03:00 (Z) for display in UTC.
However, because formatInTimeZone works internally by converting the time in the given zone to a “corresponding” local time in the system zone, this doesn’t work.
> formatInTimeZone(new Date('2023-03-12T01:05Z'), 'UTC', 'Pp z')
'03/12/2023, 1:05 AM UTC'
> formatInTimeZone(new Date('2023-03-12T02:05Z'), 'UTC', 'Pp z') // expected 2:05 AM UTC
'03/12/2023, 3:05 AM UTC'
> formatInTimeZone(new Date('2023-03-12T03:05Z'), 'UTC', 'Pp z')
'03/12/2023, 3:05 AM UTC'
> formatInTimeZone(new Date('2023-03-12T04:05Z'), 'UTC', 'Pp z')
'03/12/2023, 4:05 AM UTC'
(Using date-fns-tz@2.0.0 on Node.js 20.9.0 with America/Los_Angeles as the system time zone.)
My system time zone is
America/Los_Angeles
, where the start of daylight saving time on 2023-03-12 jumped the local time directly from 01:59 (-08:00) to 03:00 (-07:00). TheUTC
time zone had no such jump, of course, so one wouldn’t expect any issues formatting aUTC
date between 01:59 (Z) and 03:00 (Z) for display inUTC
.However, because
formatInTimeZone
works internally by converting the time in the given zone to a “corresponding” local time in the system zone, this doesn’t work.(Using date-fns-tz@2.0.0 on Node.js 20.9.0 with
America/Los_Angeles
as the system time zone.)