-
Notifications
You must be signed in to change notification settings - Fork 4.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
dateI18n
throws Moment error with String timezones
#22193
Comments
The issue is that First I thought maybe we could always rely on the int wp.date.dateI18n( 'Y-m-d h:ia', Date.now(), 'Asia/Macau' );
// Console: Moment Timezone has no data for Asia/Macau. I think either we need to bring back the timezone data, or disallow string timezones. As an aside, I'm not totally sure why |
I'm guessing they're "correct" because the timezone of your WordPress and the timezone you’re computer is in are the same.
I've tested @iandunn's issue on WordPress 5.4.1 (that is, I didn't exactly reproduce his steps) and this is working as expected: moment.tz.names().includes( 'America/Vancouver' )
» true So I really don't know which timezones are available and which aren't. Maybe someone from #12356 can shed some light on this one?
I agree. In #18982 we decided to include string timezones so that JS API resembled that of PHP (namely, |
Yeah, this is only an issue in the plugin, because 5.4.1 is built with a later version of moment-timezone. The later versions (0.5.18+, i think) load all the timezone data due to a change in how they import files. That's also why importing I've updated moment-timezone in #22866, which brings back the timezone data. |
Problem
Calling
dateI18n
-- and possibly otherdate
functions -- produces a console error, if the timezone is set to a string likeAmerica/Vancouver
. If it's set to an int like,-7
then it doesn't throw an error.Moment Timezone has no data for America/Vancouver. See http://momentjs.com/timezone/docs/#/data-loading/. index.js:6:3194
The times appear correct regardless of whether the error is shown, but I haven't tested edge cases like DST, etc.
Possibly related: #21977, #18982
Reproduction steps
Tested with Firefox and the
master
branch for Core and the plugin.America/Vancouver
.mu-plugin
:-7
then it will work without an error.In a React app, this results in an error:
...while this doesn't:
The text was updated successfully, but these errors were encountered: