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

Mocking setTimezoneOffset #341

Open
andrewplummer opened this issue Oct 23, 2020 · 5 comments
Open

Mocking setTimezoneOffset #341

andrewplummer opened this issue Oct 23, 2020 · 5 comments

Comments

@andrewplummer
Copy link

It would be very nice to have a way to mock the system timezone offset, ie. override Date.prototype.getTimezoneOffset.

I realize that this is possible and not very hard without fake-timers, however given that it hijacks the global Date object, if you were to do this the order of applying the mocks would then become a consideration (ie. if you were to mock Date.prototype.getTimezoneOffset and then call FakeTimers.install your mock would be shadowed and inaccessible).

I realize that this package is doing a lot and timezones aren't really its main intent, but since it is mocking the Date object it makes sense to me that mocking this method also could/should be something that it does.

@benjamingr
Copy link
Member

(ie. if you were to mock Date.prototype.getTimezoneOffset and then call FakeTimers.install your mock would be shadowed and inaccessible).

Why is that - the source code indicates this should work https://github.com/sinonjs/fake-timers/blob/master/src/fake-timers-src.js#L181

@andrewplummer
Copy link
Author

Ah I stand corrected! That does appear to work. Well in that case I suppose the only reason is that a clock.setSystemTimezoneOffset might be a useful addition since sinon has already gone to the trouble to create a nice API to mock Date. It's not as compelling an argument as I originally thought though so feel free to close.

Thanks for a great library!

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 25, 2020
@stale stale bot removed the stale label May 28, 2021
@fatso83 fatso83 changed the title Feature Request: mocking setTimezoneOffset Mocking setTimezoneOffset May 28, 2021
@fatso83
Copy link
Contributor

fatso83 commented Jan 28, 2022

@andrewplummer If you want to see this happening the source code is quite readable and easy to grok, so I think a PR could be whipped up in less than an hour 😉

Copy link

stale bot commented Dec 27, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants