From f584b5755ad66c5017fbf003ba98bd529afba9da Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 5 Jul 2018 23:10:01 +0000 Subject: [PATCH] Date/Time: Add support for the `c` and `r` shorthand formats in `date_i18n()`. Props Rarst, pbearne Fixes #20973 git-svn-id: https://develop.svn.wordpress.org/trunk@43434 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 3 +++ tests/phpunit/tests/date/dateI18n.php | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 9fba7917d6..8ae58299d6 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -107,6 +107,9 @@ function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa */ $req_format = $dateformatstring; + $dateformatstring = preg_replace( "/(?month ) ) && ( ! empty( $wp_locale->weekday ) ) ) { $datemonth = $wp_locale->get_month( date( 'm', $i ) ); $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth ); diff --git a/tests/phpunit/tests/date/dateI18n.php b/tests/phpunit/tests/date/dateI18n.php index 283d82adbd..c3dc1a6e77 100644 --- a/tests/phpunit/tests/date/dateI18n.php +++ b/tests/phpunit/tests/date/dateI18n.php @@ -83,4 +83,26 @@ class Tests_Date_I18n extends WP_UnitTestCase { $this->assertEquals( $datetime->format( $timezone_formats ), date_i18n( $timezone_formats ) ); } + + /** + * @dataProvider data_formats + * @ticket 20973 + */ + public function test_date_i18n_handles_shorthand_formats( $short, $full ) { + $this->assertEquals( date_i18n( $full ), date_i18n( $short ) ); + $this->assertEquals( $short, date_i18n( '\\' . $short ) ); + } + + public function data_formats() { + return array( + array( + 'c', + 'Y-m-d\TH:i:sP', + ), + array( + 'r', + 'D, d M Y H:i:s O', + ), + ); + } }