Date/Time: Add more supported formats to `wp_maybe_decline_date()`.

Props SergeyBiryukov, Rarst.
Fixes #37411.
Built from https://develop.svn.wordpress.org/trunk@45555


git-svn-id: http://core.svn.wordpress.org/trunk@45366 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-06-20 13:47:52 +00:00
parent bd239b4be8
commit a06e914bae
2 changed files with 18 additions and 3 deletions

View File

@ -219,10 +219,12 @@ function wp_maybe_decline_date( $date ) {
* translate this to 'on'. Do not translate into your own language.
*/
if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
$months = $wp_locale->month;
$months_genitive = $wp_locale->month_genitive;
// Match a format like 'j F Y' or 'j. F'
if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
$months = $wp_locale->month;
$months_genitive = $wp_locale->month_genitive;
foreach ( $months as $key => $month ) {
$months[ $key ] = '# ' . $month . '( |$)#u';
@ -234,6 +236,19 @@ function wp_maybe_decline_date( $date ) {
$date = preg_replace( $months, $months_genitive, $date );
}
// Match a format like 'F jS' or 'F j' and change it to 'j F'
if ( @preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
foreach ( $months as $key => $month ) {
$months[ $key ] = '#' . $month . ' (\d{1,2})(st|nd|rd|th)?#u';
}
foreach ( $months_genitive as $key => $month ) {
$months_genitive[ $key ] = '$1 ' . $month;
}
$date = preg_replace( $months, $months_genitive, $date );
}
}
// Used for locale-specific rules

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45554';
$wp_version = '5.3-alpha-45555';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.