Skip to content

Fixed moment timezone configuration. - #5916

Merged
jorgefilipecosta merged 1 commit into
masterfrom
fix/moment-timezone-configuration
Apr 3, 2018
Merged

jorgefilipecosta merged 1 commit into
masterfrom
fix/moment-timezone-configuration

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

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.

@jorgefilipecosta jorgefilipecosta added the [Type] Bug An existing feature does not function as intended label Mar 30, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this Mar 30, 2018
Comment thread date/index.js Outdated
offsets: [ offsets ],
};
momentLib.tz.add( momentLib.tz.pack( momentTimezone ) );
if ( settings.timezone.offset ) {

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Member Author

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.
@jorgefilipecosta
jorgefilipecosta force-pushed the fix/moment-timezone-configuration branch from 1d838bf to 7cb4021 Compare April 2, 2018 18:42

@youknowriad youknowriad left a comment

Copy link
Copy Markdown
Contributor

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.

@jorgefilipecosta
jorgefilipecosta merged commit 7c454cb into master Apr 3, 2018
@jorgefilipecosta
jorgefilipecosta deleted the fix/moment-timezone-configuration branch April 3, 2018 10:13
@jorgefilipecosta jorgefilipecosta added this to the 2.6 milestone Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants