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.

git-svn-id: https://develop.svn.wordpress.org/trunk@40324 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2017-03-24 17:31:54 +00:00
parent d0b54885a3
commit 54baae39b2
2 changed files with 2 additions and 4 deletions

View File

@ -1401,7 +1401,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
// #38883). In this case, shim the value based on the `post_date`
// field with the site's timezone offset applied.
if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
$post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_date ) - ( get_option( 'gmt_offset' ) * 3600 ) );
$post_date_gmt = get_gmt_from_date( $post->post_date );
} else {
$post_date_gmt = $post->post_date_gmt;
}

View File

@ -2242,8 +2242,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
global $wpdb;
wp_set_current_user( self::$editor_id );
update_option( 'timezone_string', '' );
update_option( 'gmt_offset', -6 );
update_option( 'timezone_string', 'America/Chicago' );
// Need to set dates using wpdb directly because `wp_update_post` and
// `wp_insert_post` have additional validation on dates.
@ -2288,7 +2287,6 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
$this->assertEquals( $post->post_date_gmt, '2016-02-23 19:00:00' );
update_option( 'timezone_string', '' );
update_option( 'gmt_offset', 0 );
}
public function test_update_post_slug() {