From a8a6a1fc00f24555d8e0214e34a8fc09b498089e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 25 Nov 2019 10:10:31 +0000 Subject: [PATCH] Date/Time: Remove `mysql2date()` usage in `get_feed_build_date()` to ensure the output includes correct timezone offset. With the changes in [45908], `mysql2date()` works correctly for all local time inputs, but should not be used for UTC time inputs. Add a unit test. Props Rarst, lisota. Merges [46756] and [46757] to the 5.3 branch. Fixes #48675. git-svn-id: https://develop.svn.wordpress.org/branches/5.3@46774 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/feed.php | 8 +++- tests/phpunit/tests/date/getFeedBuildDate.php | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/tests/date/getFeedBuildDate.php diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php index 3c88b4e1ec..ce4f1acdf4 100644 --- a/src/wp-includes/feed.php +++ b/src/wp-includes/feed.php @@ -683,7 +683,13 @@ function get_feed_build_date( $format ) { } // Determine the maximum modified time. - $max_modified_time = mysql2date( $format, max( $modified_times ), false ); + $datetime = date_create_immutable_from_format( + 'Y-m-d H:i:s', + max( $modified_times ), + new DateTimeZone( 'UTC' ) + ); + + $max_modified_time = $datetime->format( $format ); /** * Filters the date the last post or comment in the query was modified. diff --git a/tests/phpunit/tests/date/getFeedBuildDate.php b/tests/phpunit/tests/date/getFeedBuildDate.php new file mode 100644 index 0000000000..bf99ff3c26 --- /dev/null +++ b/tests/phpunit/tests/date/getFeedBuildDate.php @@ -0,0 +1,39 @@ +post->create( + array( + 'post_date' => '2018-07-22 21:13:23', + 'post_date_gmt' => '2018-07-23 03:13:23', + ) + ); + + $wp_query = new WP_Query( array( 'p' => $post_id ) ); + + $this->assertEquals( '2018-07-23T03:13:23+00:00', get_feed_build_date( DATE_RFC3339 ) ); + } +}