Make WordPress Core

Ticket #37411: wp-maybe-decline-date.patch

File wp-maybe-decline-date.patch, 2.5 KB (added by Rarst, 6 years ago)
  • src/wp-includes/functions.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    219219         * translate this to 'on'. Do not translate into your own language.
    220220         */
    221221        if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
    222                 // Match a format like 'j F Y' or 'j. F'
    223                 if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
    224                         $months          = $wp_locale->month;
    225                         $months_genitive = $wp_locale->month_genitive;
     222
     223                $months          = $wp_locale->month;
     224                $months_genitive = $wp_locale->month_genitive;
    226225
     226                // Match a format like 'j F Y' or 'j. F'
     227                if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
     228
    227229                        foreach ( $months as $key => $month ) {
    228230                                $months[ $key ] = '# ' . $month . '( |$)#u';
    229231                        }
     
    232234                                $months_genitive[ $key ] = ' ' . $month . '$1';
    233235                        }
    234236
     237                        $date = preg_replace( $months, $months_genitive, $date );
     238                }
     239
     240                // Match a format like 'F jS' or 'F j' and change it to 'j F'
     241                if ( @preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
     242                        foreach ( $months as $key => $month ) {
     243                                $months[ $key ] = '#' . $month . ' (\d{1,2})(st|nd|rd|th)?#u';
     244                        }
     245
     246                        foreach ( $months_genitive as $key => $month ) {
     247                                $months_genitive[ $key ] = '$1 ' . $month;
     248                        }
     249
    235250                        $date = preg_replace( $months, $months_genitive, $date );
    236251                }
    237252        }
  • tests/phpunit/tests/functions/maybeDeclineDate.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    33/**
    44 * @group functions.php
    55 * @group i18n
     6 * @group datetime
    67 */
    78class Tests_Functions_MaybeDeclineDate extends WP_UnitTestCase {
    89
     
    6869                return array(
    6970                        array( 'ru_RU', '21 Июнь', '21 июня' ),
    7071                        array( 'ru_RU', '1 Январь 2016', '1 января 2016' ),
     72                        array( 'ru_RU', 'Январь 1st 2016', '1 января 2016' ),
     73                        array( 'ru_RU', 'Январь 1 2016', '1 января 2016' ),
    7174                        array( 'pl_PL', '1 Styczeń', '1 stycznia' ),
    7275                        array( 'hr', '1. Siječanj', '1. siječnja' ),
    7376                        array( 'ca', '1 de abril', "1 d'abril" ),