-
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
Fixed moment timezone configuration. #5916
Conversation
date/index.js
Outdated
offsets: [ offsets ], | ||
}; | ||
momentLib.tz.add( momentLib.tz.pack( momentTimezone ) ); | ||
if ( settings.timezone.offset ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't test now but I recall the special test was here for special timezones (like UTC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @youknowriad, you are totally right this code had a bug.
The offset can be 0 in which the condition would return false and the code would not be executed. I removed the condition as if we don't initialize the timezone we have errors. I added an or to use 0 if we are in the presence of some undefined case (should never happen because get_option( 'gmt_offset', 0 ); should always return something.
When we use moment.tz.zone( settings.timezone.string ) moment returns us an object which contains the offsets property with a large array, but also returns arrays of the same sizes for untils and abbrs. When timezone was passed back to the moment (to configure it) we only passed the offsets array and we used an array with a null value for untils and an array with 'WP' for the abbrs. This made moment logic not work correctly. If besides offsets we also passback untils and abbrs arrays things work as expected. Given that our logic worked correctly when the timezone contains just the offset (a UTC value was set as timezone instead of a city), there is no need to maintain two logics because if we select a city as timezone we have access to offset anyway which was computed on the server using get_option( 'gmt_offset', 0 ); So we are changing the moment timezone configuration to rely just on the offset.
1d838bf
to
7cb4021
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Seems to work fine, thanks for the fix.
When we use moment.tz.zone( settings.timezone.string ) moment returns us an object which contains the offsets property with a large array, but also returns arrays of the same sizes for untils and abbrs. When timezone was passed back to the moment (to configure it) we only passed the offsets array and we used an array with a null value for untils and an array with 'WP' for the abbrs. This made moment logic not work correctly. If besides offsets we also passback untils and abbrs arrays things work as expected.
Given that our logic worked correctly when the timezone contains just the offset (a UTC value was set as timezone instead of a city), there is no need to maintain two logics because if we select a city as timezone we have access to offset anyway which was computed on the server using get_option( 'gmt_offset', 0 );
So we are changing the moment timezone configuration to rely just on the offset.
Fixes: #5874
How Has This Been Tested?
Set your wordpress timezone settings to a city e.g: "Lisbon".
Create a new post, write something and verify the Publish button says "Publish...", publish the post see the pre/pos publish panel works as expected.
Schedule a post to be posted after 3 minutes and after a long time verify we have now a "Schedule..." button and the schedule flow works as expected.