Date/Time: Add more supported formats to `wp_maybe_decline_date()`.
Props SergeyBiryukov, Rarst. Fixes #37411. git-svn-id: https://develop.svn.wordpress.org/trunk@45555 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
97b90a454c
commit
e283457e45
|
@ -219,11 +219,13 @@ 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' ) ) {
|
||||
// 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;
|
||||
|
||||
// Match a format like 'j F Y' or 'j. F'
|
||||
if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
|
||||
|
||||
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
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
/**
|
||||
* @group functions.php
|
||||
* @group i18n
|
||||
* @group datetime
|
||||
*/
|
||||
class Tests_Functions_MaybeDeclineDate extends WP_UnitTestCase {
|
||||
|
||||
|
@ -68,6 +69,8 @@ class Tests_Functions_MaybeDeclineDate extends WP_UnitTestCase {
|
|||
return array(
|
||||
array( 'ru_RU', '21 Июнь', '21 июня' ),
|
||||
array( 'ru_RU', '1 Январь 2016', '1 января 2016' ),
|
||||
array( 'ru_RU', 'Январь 1st 2016', '1 января 2016' ),
|
||||
array( 'ru_RU', 'Январь 1 2016', '1 января 2016' ),
|
||||
array( 'pl_PL', '1 Styczeń', '1 stycznia' ),
|
||||
array( 'hr', '1. Siječanj', '1. siječnja' ),
|
||||
array( 'ca', '1 de abril', "1 d'abril" ),
|
||||
|
|
Loading…
Reference in New Issue