date-fns-timezone
date-fns-timezone copied to clipboard
formatToTimeZone depends unexpectedly on system timezone
Using formatToTimeZone to convert an absolute time value to a date/time localised to a timezone gives different results depending on system timezone.
When converting an absolute number of milliseconds since epoch into an arbitrary timezone, I would not expect the local timezone to have any effect.
For example, compare system timezone as Europe/London:
$ TZ=Europe/London node
> const {formatToTimeZone} = require('date-fns-timezone');
undefined
> formatToTimeZone( 1585422000000, 'YYYY-MM-DDTHH:mm:ssZ', {timeZone: 'Pacific/Auckland'})
'2020-03-29T09:00:00+13:00'
with system timezone America/New_York:
$ TZ=America/New_York node
> const {formatToTimeZone} = require('date-fns-timezone');
undefined
> formatToTimeZone( 1585422000000, 'YYYY-MM-DDTHH:mm:ssZ', {timeZone: 'Pacific/Auckland'})
'2020-03-29T08:00:00+13:00'
The hour part is different : 09 vs 08
According to [1] the correct value is 08.
[1] https://www.epochconverter.com/timezones?q=1585422000000&tz=Pacific%2FAuckland