diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 26b78c5e35..89b4ccb3e2 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -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; } diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index abc30d40ce..409982eed8 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -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() {