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

Time zone offset is added in the wrong direction when parsing dates #77

Closed
jonathanperret opened this issue Jan 29, 2017 · 1 comment · Fixed by #78
Closed

Time zone offset is added in the wrong direction when parsing dates #77

jonathanperret opened this issue Jan 29, 2017 · 1 comment · Fixed by #78

Comments

@jonathanperret
Copy link
Contributor

Currently, to compute the UTC date, yaml.js adds the time zone offset found in a date literal to the date. Therefore, 2017-01-01T10:00:00+05:00 is parsed as 2017-01-01T15:00:00.000Z:

$ node -p "require('yamljs').parse('date: 2017-01-01T10:00:00+05:00')"
{ date: 2017-01-01T15:00:00.000Z }

This is wrong because +05:00 means the date is written in the local time of the UTC+5 time zone, meaning one should subtract five hours from the local time to get the UTC time (see e.g. https://www.w3.org/TR/NOTE-datetime).

For reference, here's the Date constructor handling the offset correctly:

$ node -p "new Date('2017-01-01T10:00:00+05:00')"
2017-01-01T05:00:00.000Z
jeremyfa added a commit that referenced this issue Mar 31, 2017
Fix reversed application of timezone offset (#77)
@jonathanperret
Copy link
Contributor Author

❤️

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

Successfully merging a pull request may close this issue.

1 participant