Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Z in the format pattern (using time zone) throws an error #1473

Closed
micaelmbagira opened this issue Oct 11, 2019 · 6 comments
Closed

Using Z in the format pattern (using time zone) throws an error #1473

micaelmbagira opened this issue Oct 11, 2019 · 6 comments

Comments

@micaelmbagira
Copy link

I am running this example taken from https://date-fns.org/v2.4.1/docs/Time-Zones

const { zonedTimeToUtc, utcToZonedTime, format } = require('date-fns-tz');

const zonedDate = utcToZonedTime(Date.now(), 'Europe/Berlin');
const pattern = 'd.m.yyyy HH:mm:ss.SSS [GMT]Z (z)';
const output = format(zonedDate, pattern, { timeZone: 'Europe/Berlin' });

and I get the following error

RangeError: Format string contains an unescaped latin alphabet character Z

Even though Z is in the list of available tokens: https://date-fns.org/v2.4.1/docs/format

@dkozickis
Copy link
Contributor

Hi @micaelmbagira! Docs seem to be slightly out of date.

  • Z (uppercase) is not accepted anymore (docs are correct on that)
  • You'll have to use XXX for GMT offset

Following should work

const { zonedTimeToUtc, utcToZonedTime, format } = require('date-fns-tz');

const zonedDate = utcToZonedTime(Date.now(), "Europe/Berlin");
const pattern = "d.m.yyyy HH:mm:ss.SSS 'GMT' XXX (z)";
const output = format(zonedDate, pattern, { timeZone: "Europe/Berlin" });

See repro here - https://codesandbox.io/embed/adoring-hermann-yb7fx

We'll update the docs.

@masbaehr
Copy link

masbaehr commented May 5, 2020

still wrong as of today: https://date-fns.org/v2.12.0/docs/Time-Zones

@kossnocorp
Copy link
Member

@masbaehr sorry I must have missed a pull-request from you.

@kossnocorp
Copy link
Member

@masbaehr weird, I couldn't find it so I did it myself ¯\(ツ)

@masbaehr
Copy link

masbaehr commented May 5, 2020

@masbaehr weird, I couldn't find it so I did it myself ¯_(ツ)_/¯

Haha of course you did not find it - there is none. I just mentioned it as i came across it while switching from moment to date-fns ;D since the pattern is "Z" there

@kossnocorp
Copy link
Member

Ok, I see. You just sounded like someone who's tried to help but got ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants