From c04b63b8e6877a421b0beacd15b13ca79ec972c9 Mon Sep 17 00:00:00 2001
From: Andrey Savchenko <contact@rarst.net>
Date: Thu, 28 Jun 2018 12:03:20 +0300
Subject: [PATCH 1/2] Fixed behavior of gmt argument in date_i18n() for correct
timezone output.
---
src/wp-includes/functions.php | 5 ++++-
tests/phpunit/tests/date/dateI18n.php | 4 +++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 3c4a301298..5d1bf445cf 100644
a
|
b
|
function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa |
126 | 126 | $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' ); |
127 | 127 | $timezone_formats_re = implode( '|', $timezone_formats ); |
128 | 128 | if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) { |
129 | | $timezone_string = get_option( 'timezone_string' ); |
| 129 | $timezone_string = get_option( 'timezone_string' ); |
| 130 | if ( false === $timestamp_with_offset && $gmt ) { |
| 131 | $timezone_string = 'UTC'; |
| 132 | } |
130 | 133 | if ( $timezone_string ) { |
131 | 134 | $timezone_object = timezone_open( $timezone_string ); |
132 | 135 | $date_object = date_create( null, $timezone_object ); |
diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php
index e92f58de6f..9460f8fdcf 100644
a
|
b
|
public function test_should_use_custom_timestamp() { |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function test_date_should_be_in_gmt() { |
17 | | $this->assertEquals( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s', false, true ) ), 'The dates should be equal', 2 ); |
| 17 | update_option( 'timezone_string', 'America/Regina' ); |
| 18 | |
| 19 | $this->assertEquals( date( DATE_RFC3339 ), date_i18n( DATE_RFC3339, false, true ), 'The dates should be equal' ); |
18 | 20 | } |
19 | 21 | |
20 | 22 | public function test_custom_timestamp_ignores_gmt_setting() { |
From 2a3f9efc40a4db1eec124bdf28efe6a1c190977c Mon Sep 17 00:00:00 2001
From: Andrey Savchenko <contact@rarst.net>
Date: Thu, 28 Jun 2018 12:41:16 +0300
Subject: [PATCH 2/2] Adjusted gmt argument tests.
---
tests/phpunit/tests/date/dateI18n.php | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php
index 9460f8fdcf..da64bd6502 100644
a
|
b
|
public function test_should_use_custom_timestamp() { |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function test_date_should_be_in_gmt() { |
17 | | update_option( 'timezone_string', 'America/Regina' ); |
18 | | |
19 | | $this->assertEquals( date( DATE_RFC3339 ), date_i18n( DATE_RFC3339, false, true ), 'The dates should be equal' ); |
| 17 | $this->assertEquals( strtotime( date( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2 ); |
20 | 18 | } |
21 | 19 | |
22 | 20 | public function test_custom_timestamp_ignores_gmt_setting() { |
… |
… |
public function test_custom_timezone_setting() { |
32 | 30 | public function test_date_should_be_in_gmt_with_custom_timezone_setting() { |
33 | 31 | update_option( 'timezone_string', 'America/Regina' ); |
34 | 32 | |
35 | | $this->assertEquals( strtotime( date( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s', false, true ) ), 'The dates should be equal', 2 ); |
| 33 | $this->assertEquals( strtotime( date( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2 ); |
36 | 34 | } |
37 | 35 | |
38 | 36 | public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() { |