Make WordPress Core

Ticket #37440: trac-37440.diff

File trac-37440.diff, 1.6 KB (added by Rarst, 6 years ago)

Change to gmdate() in implementation with a unit test.

  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 3c4a301298..bf814d5baf 100644
    a b function current_time( $type, $gmt = 0 ) { 
    6969                case 'timestamp':
    7070                        return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    7171                default:
    72                         return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
     72                        return ( $gmt ) ? gmdate( $type ) : gmdate( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
    7373        }
    7474}
    7575
  • new file tests/phpunit/tests/date/currentTime.php

    diff --git a/tests/phpunit/tests/date/currentTime.php b/tests/phpunit/tests/date/currentTime.php
    new file mode 100644
    index 0000000000..209eb128c6
    - +  
     1<?php
     2
     3/**
     4 * @group date
     5 * @group datetime
     6 */
     7class Tests_Date_CurrentTime extends WP_UnitTestCase {
     8
     9        public function test_should_work_with_changed_timezone() {
     10
     11                $format          = 'Y-m-d H:i:s';
     12                $timezone_string = 'America/Regina';
     13                update_option( 'timezone_string', $timezone_string );
     14                $datetime = new DateTime( 'now', new DateTimeZone( $timezone_string ) );
     15
     16                date_default_timezone_set( $timezone_string );
     17                $this->assertEquals( gmdate( $format ), current_time( $format, true ) );
     18                $this->assertEquals( $datetime->format( $format ), current_time( $format ) );
     19
     20                date_default_timezone_set( 'UTC' );
     21                $this->assertEquals( gmdate( $format ), current_time( $format, true ) );
     22                $this->assertEquals( $datetime->format( $format ), current_time( $format ) );
     23        }
     24}