Date / Time: Remove usage of mysql2date in generate_postdata method.

Remove usage of `mysql2date` in `generate_postdata`. `mysql2date` has a performance overhead, as it creates a `DateTimeZone` object each time it is called. Use a simple 
sub string function to generate the values needed for the `currentmonth` and `currentday` global variables. 

Props spacedmonkey, Rarst, SergeyBiryukov, flixos90.
Fixes #57683.
Built from https://develop.svn.wordpress.org/trunk@55558


git-svn-id: http://core.svn.wordpress.org/trunk@55070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2023-03-17 15:58:23 +00:00
parent 215ecfc7ad
commit 0e55b6ab84
2 changed files with 17 additions and 6 deletions

View File

@ -4714,11 +4714,22 @@ class WP_Query {
$authordata = get_userdata( $post->post_author ); $authordata = get_userdata( $post->post_author );
$currentday = mysql2date( 'd.m.y', $post->post_date, false ); $currentday = false;
$currentmonth = mysql2date( 'm', $post->post_date, false ); $currentmonth = false;
$numpages = 1;
$multipage = 0; $post_date = $post->post_date;
$page = $this->get( 'page' ); if ( ! empty( $post_date ) && '0000-00-00 00:00:00' !== $post_date ) {
// Avoid using mysql2date for performance reasons.
$currentmonth = substr( $post_date, 5, 2 );
$day = substr( $post_date, 8, 2 );
$year = substr( $post_date, 2, 2 );
$currentday = sprintf( '%s.%s.%s', $day, $currentmonth, $year );
}
$numpages = 1;
$multipage = 0;
$page = $this->get( 'page' );
if ( ! $page ) { if ( ! $page ) {
$page = 1; $page = 1;
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.3-alpha-55557'; $wp_version = '6.3-alpha-55558';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.