-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Setting identical timezone to the current timezone subtracts an hour #1690
Comments
Looks like outputting the desired timezone fixes this problem: https://codesandbox.io/s/cold-cherry-s3l4y?file=/src/App.js
|
As far as I can tell, the As an aside, a quick-fix for this particular issue could be to have the |
I was about to open an issue with respect to dates being parsed to/from unix timestamps being wrong after a timezone offset is applied. Came across this issue - it appears to be due to this bug. My returned times are off by one hour - out of curiosity I called Interestingly enough, version 1.0.4 does not seem to have the same behavior in my test. It is ahead by an hour, instead of behind. However multiple calls to I noticed in v1.0.5's commit notes: this is quite possibly where the behavior changed. |
Describe the bug
In the timezone plugin, setting a timezone to a date can result in subtracting an hour when it wasn't supposed to be.
The culprit is this line: https://github.com/iamkun/dayjs/blob/dev/src/plugin/timezone/index.js#L98
Doing
const target = date.toLocalString('en-US', { timeZone: timezone})
will return a string without any timezone data so when the code executes the next line withnew Date(target)
, that date object is no longer in the correct timezone.Recreated this behavior here:
https://codesandbox.io/s/damp-cherry-lzv2z?file=/src/App.js
I inspected the objects -- they both are set in the correct timezone for the date (
PDT
) with identical offset but their Unix timestamps are off. That shouldn't happen when setting timezone data.Expected behavior
Setting an identical timezone to a date should not change the time.
Information
The text was updated successfully, but these errors were encountered: