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

getTimezoneOffset returns -0 for UTC #51

Open
jamesball27 opened this issue Oct 25, 2021 · 0 comments
Open

getTimezoneOffset returns -0 for UTC #51

jamesball27 opened this issue Oct 25, 2021 · 0 comments

Comments

@jamesball27
Copy link

jamesball27 commented Oct 25, 2021

Steps to reproduce:

import timezoneMock from 'timezone-mock';

timezoneMock.register('UTC');
new Date().getTimezoneOffset(); // returns -0

this causes issues when using jest because toEqual uses Object.is under the hood, so this assertion fails:

timezoneMock.register('UTC');
const offset = new Date().getTimezoneOffset();
expect(offset).toEqual(0); // fails because Object.is(-0, 0) return false

and instead an ugly workaround is required:

expect(offset === 0).toBe(true);

I'd expect getTimezoneOffset to return 0 for UTC instead of -0
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset#negative_values_and_positive_values

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