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

zonedTimeToUtc is not working for timeZone Etc/GMT+6 #33

Closed
zitniak opened this issue Nov 26, 2019 · 5 comments
Closed

zonedTimeToUtc is not working for timeZone Etc/GMT+6 #33

zitniak opened this issue Nov 26, 2019 · 5 comments

Comments

@zitniak
Copy link

zitniak commented Nov 26, 2019

zonedTimeToUtc('2019-11-26T10:00:00', 'America/Chicago'); // returns correct 2019-11-26T16:00:00.000Z

zonedTimeToUtc('2019-11-26T10:00:00', 'Etc/GMT+6'); // returns incorrect 2019-11-26T10:00:000Z, timezone Etc/GMT+6 is silently ignored. Nor Unsupported time zone specified is thrown. It should return too 2019-11-26T16:00:00.000Z. It's Central Standard Time (CST).

Etc/GMT+6 is correct timezone identification by IANA database https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

findTimeZone('Etc/GMT+6') from require('timezone-support') confirming that timezone exists.

zonedTimeToUtc is not working generally with timezones 'Etc/GMT+X'.

Versions:
date-fns-tz: v.1.0.8
date-fns: v.2.8.1

@marnusw
Copy link
Owner

marnusw commented Nov 26, 2019

findTimeZone('Etc/GMT-6') from require('timezone-support') confirming that timezone exists.

Please see if you can get this time zone to work with Intl.DateTimeFormat directly on the platform(s) you are targeting. If that fails then there is nothing to be done in date-fns-tz at the moment because it simply uses Intl.DateTimeFormat without any other checks.

date-fns: v.1.30.1

This library was designed for use with date-fns v2. There is no guarantee it will work as expected with v1. (Although that does not seem to be the issue in this particular case.)

@zitniak
Copy link
Author

zitniak commented Nov 27, 2019

Thanks, sorry I am using date-fns:"2.8.1" (I wrongly copy-pasted the version, I fixed my description).

I've tried:

var date = new Date(Date.UTC(2019, 11, 26, 10, 0, 0));
var expectedResult = Intl.DateTimeFormat(undefined, {
    'Etc/GMT+6'
}).format(date);

It throws the error: RangeError: Expected Area/Location(/Location)* for time zone, got Etc/GMT+6

Now I believe the zonedTimeToUtc should throw at least an error too, because the error is hidden.

BTW Moment.js handles moment.tz('2019-11-26T10:00:00', 'Etc/GMT+6') correctly, it returns 2019-11-26T16:00:00.000Z

@zitniak zitniak changed the title zonedTimeToUtc is not working for timeZone Etc/GMT-6 zonedTimeToUtc is not working for timeZone Etc/GMT+6 Nov 27, 2019
@nilamsavani
Copy link

Facing same problem. Any solution?

@NellyHayrapetyan
Copy link

findTimeZone('Etc/GMT-6') from require('timezone-support') confirming that timezone exists.

Please see if you can get this time zone to work with Intl.DateTimeFormat directly on the platform(s) you are targeting. If that fails then there is nothing to be done in date-fns-tz at the moment because it simply uses Intl.DateTimeFormat without any other checks.

date-fns: v.1.30.1

This library was designed for use with date-fns v2. There is no guarantee it will work as expected with v1. (Although that does not seem to be the issue in this particular case.)

@marnusw I tried to do this utcToZonedTime(1581509131067, 'Etc/GMT-6'))
It returns Wed Feb 12 2020 12:05:31 (ignoring the given timezone),

Here is the Intl.DateTimeFormat implementation

Intl.DateTimeFormat(undefined, {
      year: 'numeric',
      month: 'numeric',
      day: 'numeric',
      hour: 'numeric',
      minute: 'numeric',
      second: 'numeric',
      timeZone: 'Etc/GMT-6',
    }).format(1581509131067)

which understands the timezone and returns 2/12/2020, 6:05:31 PM

@Pustelto
Copy link

Pustelto commented Feb 4, 2021

This actually seems like problem with tzParseTimezone function. I have tried to check it's regexp pattern for timezoneIANA and it is not picking up the Etc.

Snímek obrazovky 2021-02-04 v 13 43 17

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

No branches or pull requests

5 participants