Make WordPress Core


Ignore:
Timestamp:
05/26/2019 12:11:37 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Replace all instances of date() with gmdate().

Use of date() in core depends on PHP timezone set to UTC and not changed by third party code (which cannot be guaranteed).

gmdate() is functionally equivalent, but is not affected by PHP timezone setting: it's always UTC, which is the exact behavior the core needs.

Props nielsdeblaauw, Rarst.
Fixes #46438. See #44491.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r44933 r45424  
    20112011        $this->assertEquals( 'draft', $new_post->post_status );
    20122012        // Confirm dates are shimmed for gmt_offset
    2013         $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) );
    2014         $post_date_gmt     = date( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) );
     2013        $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $new_post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) );
     2014        $post_date_gmt     = gmdate( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) );
    20152015
    20162016        $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] );
     
    27372737
    27382738        // The modified date should equal the current time.
    2739         $this->assertEquals( date( 'Y-m-d', strtotime( mysql_to_rfc3339( $expected_modified ) ) ), date( 'Y-m-d', strtotime( $data['modified'] ) ) );
    2740         $this->assertEquals( date( 'Y-m-d', strtotime( $expected_modified ) ), date( 'Y-m-d', strtotime( $new_post->post_modified ) ) );
     2739        $this->assertEquals( gmdate( 'Y-m-d', strtotime( mysql_to_rfc3339( $expected_modified ) ) ), gmdate( 'Y-m-d', strtotime( $data['modified'] ) ) );
     2740        $this->assertEquals( gmdate( 'Y-m-d', strtotime( $expected_modified ) ), gmdate( 'Y-m-d', strtotime( $new_post->post_modified ) ) );
    27412741    }
    27422742
Note: See TracChangeset for help on using the changeset viewer.