-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
__getExperimentalSettings timezone offset may be a string or integer #21977
Comments
I can confirm this issue and, as pointed out by @jeremyfelt, the value provided by Tests in There's two options to fix this one:
I personally think WordPress should always provide a consistent value (namely, a number and not a string). But, regardless of that, should we also add a safe guard in |
I just ran into this when trying to figure out why a site shows different times when using "Vancouver" vs "UTC-7". I've pushed a PR that converts the offset to a number before using it in |
cc @noisysocks as he's made some changes in #43005 related to this issue |
In #43005 I updated the types to reflect reality, but agree it should always be a number.
Doing both sounds good to me 🙂 |
Sounds good to me too! Has anyone involved in this conversation got any capacity to work on this? It looks like some work had already been started in #25684 (which got approved, but never merged) |
I fixed the call to |
@noisysocks, does this mean we can close #25684? |
I think #25684 addresses the first option in #21977 (comment). |
I've tested all of these with |
Describe the bug
The value provided by
wp.date.__getExperimentalSettings.timezone.offset
differs in type depending on the site's timezone setting.America/Los_Angeles
set through General Settings in the WordPress admin results in an integer offset value of-7
(currently in DST).UTC-7
results in a string offset value of"-7"
.UTC
results in an integer offset value of0
.UTC+0
results in a string offset value of"0"
.If this data is passed directly to something like
moment().utcOffset()
, which expects either an integer or a string formatted like"-07:00"
, then the returned object will not contain the expected offset information.Any of these values can be passed through
Number()
or converted to minutes via* 60
, which moment also understands, so I could see how this isn't necessarily a bug bug, but having this documented here may help someone else who started questioning the world a bit. :)Expected behavior
In a perfect world,
wp.date.__getExperimentalSettings.timezone.offset
would always be an integer. In a more perfect world, computers would never think we mean "-7" when we type -7. 😀Edited March 25, 2021: I'm not sure how
__getExperimentalOffset()
got into my head, but this should all be__getExperimentalSettings().timezone.offset
. I've edited the title and description to clarify.The text was updated successfully, but these errors were encountered: