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.
Fixes #48675.

git-svn-id: https://develop.svn.wordpress.org/trunk@46756 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-11-21 13:16:50 +00:00
parent 065a181fc0
commit 6ce8175456
2 changed files with 46 additions and 1 deletions

View File

@ -682,7 +682,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.

View File

@ -0,0 +1,39 @@
<?php
/**
* @group date
* @group datetime
*/
class Tests_Date_Get_Feed_Build_Date extends WP_UnitTestCase {
function tearDown() {
global $wp_query;
update_option( 'timezone_string', 'UTC' );
unset( $wp_query );
parent::tearDown();
}
/**
* @ticket 48675
*/
public function test_should_return_correct_feed_build_date() {
global $wp_query;
$timezone = 'America/Chicago';
update_option( 'timezone_string', $timezone );
$post_id = self::factory()->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 ) );
}
}