Make WordPress Core

Changeset 46577


Ignore:
Timestamp:
10/25/2019 11:03:13 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Make sure date_i18n() correctly handles zero timestamp after [45901].

Props soulseekah, gravityview, Rarst.
Reviewed by azaozz, SergeyBiryukov.
Fixes #28636.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r46569 r46577  
    177177    if ( 'U' === $format ) {
    178178        $date = $timestamp;
    179     } elseif ( $gmt && ! $timestamp_with_offset ) { // Current time in UTC.
     179    } elseif ( $gmt && false === $timestamp_with_offset ) { // Current time in UTC.
    180180        $date = wp_date( $format, null, new DateTimeZone( 'UTC' ) );
    181     } elseif ( ! $timestamp_with_offset ) { // Current time in site's timezone.
     181    } elseif ( false === $timestamp_with_offset ) { // Current time in site's timezone.
    182182        $date = wp_date( $format );
    183183    } else {
  • trunk/tests/phpunit/tests/date/dateI18n.php

    r45914 r46577  
    1818
    1919        $this->assertEquals( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5 );
     20    }
     21
     22    /**
     23     * @ticket 28636
     24     */
     25    public function test_should_handle_zero_timestamp() {
     26        $timezone = 'Europe/Kiev';
     27        update_option( 'timezone_string', $timezone );
     28
     29        $datetime = DateTimeImmutable::createFromFormat(
     30            'Y-m-d H:i:s',
     31            '1970-01-01 00:00:00',
     32            new DateTimeZone( $timezone )
     33        );
     34        $rfc3339  = $datetime->format( DATE_RFC3339 );
     35
     36        $this->assertEquals( 0, date_i18n( 'U', 0 ) );
     37        $this->assertEquals( $rfc3339, date_i18n( DATE_RFC3339, 0 ) );
    2038    }
    2139
Note: See TracChangeset for help on using the changeset viewer.