prantlf / date-fns-timezone

Parsing and formatting date strings using IANA time zones for date-fns.
MIT License
136 stars 18 forks source link

Timezone formatted incorrectly for timezones that are not rounded to a minute offset of UTC #21

Open 0xR opened 4 years ago

0xR commented 4 years ago

For example Amsterdam time before July 1937 is GMT +0h 19m 32.13s.

This means you get a partial minute which does not seem valid.

Example:

import {
  formatToTimeZone
} from 'date-fns-timezone';

console.log(
  formatToTimeZone(new Date(1937, 0), 'YYYY-MM-DDZ', {
   timeZone: 'Europe/Amsterdam',
 }),
);

Gives: 1937-01-01+00:19.533333333333335

0xR commented 4 years ago

My current workaround is rather pragmatic:

function roundAmsterdamTime(awsDate: string): string {
  return awsDate.replace(/:19\.5.*/, ':20');
}