WordPress.org

Make WordPress Core

Ticket #38771: trac-38771.diff

File trac-38771.diff, 3.2 KB (added by Rarst, 15 months ago)

Added improved inline doc for gmt argument.

  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 3c4a301298..4f30d98d13 100644
    a b function current_time( $type, $gmt = 0 ) { 
    8888 * @param string   $dateformatstring      Format to display the date.
    8989 * @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset in seconds.
    9090 *                                        Default false.
    91  * @param bool     $gmt                   Optional. Whether to use GMT timezone. Default false.
     91 * @param bool     $gmt                   Optional. Whether to use GMT timezone. Only applies if timestamp is not provided. Default false.
    9292 *
    9393 * @return string The date, translated if locale specifies it.
    9494 */
    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 );
    function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa 
    150153         * @param string $j          Formatted date string.
    151154         * @param string $req_format Format to display the date.
    152155         * @param int    $i          A sum of Unix timestamp and timezone offset in seconds.
    153          * @param bool   $gmt        Whether to convert to GMT for time. Default false.
     156         * @param bool   $gmt        Whether to use GMT timezone. Only applies if timestamp was not provided. Default false.
    154157         */
    155158        $j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
    156159        return $j;
  • tests/phpunit/tests/date/dateI18n.php

    diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php
    index e92f58de6f..da64bd6502 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                $this->assertEquals( strtotime( date( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2 );
    1818        }
    1919
    2020        public function test_custom_timestamp_ignores_gmt_setting() {
    public function test_custom_timezone_setting() { 
    3030        public function test_date_should_be_in_gmt_with_custom_timezone_setting() {
    3131                update_option( 'timezone_string', 'America/Regina' );
    3232
    33                 $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 );
    3434        }
    3535
    3636        public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() {