Make WordPress Core


Ignore:
Timestamp:
07/03/2018 03:58:58 PM (6 years ago)
Author:
flixos90
Message:

Date/Time: Add support for gmt_offset to date_i18n().

Prior to this change, date_i18n() only supported the timezone_string option, causing incorrect timezones to appear in formatted dates on sites that still rely on the gmt_offset option.

Props Rarst.
Fixes #34835.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/dateI18n.php

    r42343 r43387  
    6868        $this->assertEquals( '2012-12-01 00:00:00 CST -06:00 America/Regina', date_i18n( 'Y-m-d H:i:s T P e', strtotime( '2012-12-01 00:00:00' ) ) );
    6969    }
     70
     71    /**
     72     * @ticket 34835
     73     */
     74    public function test_gmt_offset_should_output_correct_timezone() {
     75        $timezone_formats = 'P I O T Z e';
     76        $timezone_string  = 'America/Regina';
     77        $datetimezone     = new DateTimeZone( $timezone_string );
     78        update_option( 'timezone_string', '' );
     79        $offset = $datetimezone->getOffset( new DateTime() ) / 3600;
     80        update_option( 'gmt_offset', $offset );
     81        $datetime = new DateTime( 'now', $datetimezone );
     82        $datetime = new DateTime( $datetime->format( 'P' ) );
     83
     84        $this->assertEquals( $datetime->format( $timezone_formats ), date_i18n( $timezone_formats ) );
     85    }
    7086}
Note: See TracChangeset for help on using the changeset viewer.