WordPress.org

Make WordPress Core

Changeset 40324


Ignore:
Timestamp:
03/24/2017 05:31:54 PM (2 years ago)
Author:
swissspidy
Message:

REST API: Use get_gmt_from_date() when preparing a draft post for response.

This prevents wrong dates when dealing with DST, see [40115] and [40284].

Props nerrad.
Fixes #40136.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r40306 r40324  
    14021402            // field with the site's timezone offset applied.
    14031403            if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
    1404                 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_date ) - ( get_option( 'gmt_offset' ) * 3600 ) );
     1404                $post_date_gmt = get_gmt_from_date( $post->post_date );
    14051405            } else {
    14061406                $post_date_gmt = $post->post_date_gmt;
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r40284 r40324  
    22432243
    22442244        wp_set_current_user( self::$editor_id );
    2245         update_option( 'timezone_string', '' );
    2246         update_option( 'gmt_offset', -6 );
     2245        update_option( 'timezone_string', 'America/Chicago' );
    22472246
    22482247        // Need to set dates using wpdb directly because `wp_update_post` and
     
    22892288
    22902289        update_option( 'timezone_string', '' );
    2291         update_option( 'gmt_offset', 0 );
    22922290    }
    22932291
Note: See TracChangeset for help on using the changeset viewer.