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

parseZone doesn't do what is expected #757

Open
cogans2 opened this issue Jan 20, 2023 · 3 comments
Open

parseZone doesn't do what is expected #757

cogans2 opened this issue Jan 20, 2023 · 3 comments

Comments

@cogans2
Copy link

cogans2 commented Jan 20, 2023

Expectation: "Moment's string parsing functions like moment(string) and moment.utc(string) accept offset information if provided, but convert the resulting Moment object to local or UTC time. In contrast, moment.parseZone() parses the string but keeps the resulting Moment object in a fixed-offset timezone with the provided offset in the string. " derived from moment docs

locale: EST
moment.parseZone("2023-01-20T00:00:00.000Z") // output Fri Jan 20 2023 00:00:00 GMT+0000

Actual: moment.parseZone() applies the timezone difference to the moment it creates in addition to converting the timezone to local.
moment.parseZone("2023-01-20T00:00:00.000Z") // output Thu Jan 19 2023 14:00:00 GMT-0500

@varunmulay22
Copy link

@cogans2 You sure about this?
Screenshot 2023-03-29 at 12 53 55 PM

@cogans2
Copy link
Author

cogans2 commented Mar 29, 2023

I am sorry for the confusion. Let me clarify. The defect concerns moment(string) vs moment.parseZone(string). You are correct that moment() and moment.parseZone() are identical in behavior and working as expected, but unfortunately, it's irrelevant to the defect I provided. Please read over my issue again and let me know if you have any questions. Thanks!

@gilmoreorless
Copy link
Member

Where are you seeing the reported output? moment.parseZone() returns a moment object, which still needs further formatting to produce a string (e.g. by using .format(string) or .toISOString()).

In my environment using moment 2.29.4 I get the following results:

moment("2023-01-20T00:00:00.000Z").format();            // "2023-01-20T11:00:00+11:00"
moment.parseZone("2023-01-20T00:00:00.000Z").format();  // "2023-01-20T00:00:00Z" 

This matches the description in the documentation.

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

3 participants