WordPress.org

Make WordPress Core

Ticket #28636: 28636-handle-zero-timestamp.patch

File 28636-handle-zero-timestamp.patch, 1.9 KB (added by Rarst, 13 months ago)
  • src/wp-includes/functions.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    176176         */
    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 {
    184184                /*
  • tests/phpunit/tests/date/dateI18n.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    1919                $this->assertEquals( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5 );
    2020        }
    2121
     22        public function test_should_handle_zero_timestamp() {
     23                $timezone = 'Europe/Kiev';
     24                update_option( 'timezone_string', $timezone );
     25
     26                $datetime = DateTimeImmutable::createFromFormat(
     27                        'Y-m-d H:i:s',
     28                        '1970-01-01 00:00:00',
     29                        new DateTimeZone( $timezone )
     30                );
     31                $rfc3339  = $datetime->format( DATE_RFC3339 );
     32
     33                $this->assertEquals( 0, date_i18n( 'U', 0 ) );
     34                $this->assertEquals( $rfc3339, date_i18n( DATE_RFC3339, 0 ) );
     35        }
     36
    2237        public function test_should_format_date() {
    2338                $this->assertEquals( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 );
    2439        }