Make WordPress Core

Ticket #38771: trac-38771.patch

File trac-38771.patch, 3.5 KB (added by Rarst, 6 years ago)

Added unit test for gmt argument fix.

  • src/wp-includes/functions.php

    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 
    126126        $timezone_formats    = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
    127127        $timezone_formats_re = implode( '|', $timezone_formats );
    128128        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                }
    130133                if ( $timezone_string ) {
    131134                        $timezone_object = timezone_open( $timezone_string );
    132135                        $date_object     = date_create( null, $timezone_object );
  • tests/phpunit/tests/date/dateI18n.php

    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() { 
    1414        }
    1515
    1616        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' );
    1820        }
    1921
    2022        public function test_custom_timestamp_ignores_gmt_setting() {
  • tests/phpunit/tests/date/dateI18n.php

    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() { 
    1414        }
    1515
    1616        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 );
    2018        }
    2119
    2220        public function test_custom_timestamp_ignores_gmt_setting() {
    public function test_custom_timezone_setting() { 
    3230        public function test_date_should_be_in_gmt_with_custom_timezone_setting() {
    3331                update_option( 'timezone_string', 'America/Regina' );
    3432
    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 );
    3634        }
    3735
    3836        public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() {