From 7c454cba7bd61bb9d388301f2031efea76683cc9 Mon Sep 17 00:00:00 2001 From: Jorge Date: Tue, 3 Apr 2018 11:12:55 +0100 Subject: [PATCH] Fixed moment timezone configuration. (#5916) 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. --- date/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/date/index.js b/date/index.js index 87bb5442b31095..3c8cb2bc37c7e6 100644 --- a/date/index.js +++ b/date/index.js @@ -5,14 +5,12 @@ import 'moment-timezone/moment-timezone-utils'; export const settings = window._wpDateSettings; // Create WP timezone based off dateSettings. -const offsets = ( settings.timezone.string ) ? momentLib.tz.zone( settings.timezone.string ).offsets : [ -settings.timezone.offset * 60 ]; -const momentTimezone = { +momentLib.tz.add( momentLib.tz.pack( { name: 'WP', abbrs: [ 'WP' ], untils: [ null ], - offsets: [ offsets ], -}; -momentLib.tz.add( momentLib.tz.pack( momentTimezone ) ); + offsets: [ -settings.timezone.offset * 60 || 0 ], +} ) ); // Create a new moment object which mirrors moment but includes // the attached timezone, instead of setting a default timezone on