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

Reversed fromUTC fallback logic #679

Open
markdascher opened this issue Oct 29, 2021 · 0 comments
Open

Reversed fromUTC fallback logic #679

markdascher opened this issue Oct 29, 2021 · 0 comments

Comments

@markdascher
Copy link

This fallback logic seems to be adding the tzOffset when it should be subtracting. At least, that would give a more consistent result. There may be some purpose for adding the tzOffset, but I'm not sure what that is.

The following examples are in the EDT (-04:00) time zone. The expected behavior is for the second and third results to match.

Chrome

new Date('10 20 2021 08:00').toISOString()
// 2021-10-20T12:00:00.000Z

Date.create('10 20 2021 08:00', { fromUTC: true }).toISOString()
// 2021-10-20T16:00:00.000Z
// Adds four hours instead of subtracting four hours.

Date.create('10.20.2021 08:00', { fromUTC: true }).toISOString()
// 2021-10-20T08:00:00.000Z
// Sugar's native fromUTC parsing results in a toISOString that matches the input.

Safari

This is just to prove we're falling back to browser-specific parsing.

new Date('10 20 2021 08:00')
// Invalid Date

Date.create('10 20 2021 08:00', { fromUTC: true })
// Invalid Date

Date.create('10.20.2021 08:00', { fromUTC: true }).toISOString()
// 2021-10-20T08:00:00.000Z
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

1 participant