WordPress.org

Make WordPress Core

Ticket #22225: 22225.patch

File 22225.patch, 5.2 KB (added by realloc, 5 years ago)

Patch and Unit tests

  • src/wp-includes/functions.php

     
    111111        if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
    112112                $datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );
    113113                $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
     114                $datemonth_ordinal = $wp_locale->get_month_ordinal( $datefunc( 'm', $i ) );
    114115                $dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) );
    115116                $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
    116117                $datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) );
     
    120121                $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
    121122                $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
    122123                $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
     124                $dateformatstring = preg_replace( "/([^\\\])S/", "\\1" . backslashit( $datemonth_ordinal ), $dateformatstring );
    123125                $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
    124126                $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
    125127
     
    51615163        // Strip timezone information
    51625164        return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
    51635165}
     5166
  • tests/phpunit/tests/functions.php

     
    717717                the_date( 'Y', 'before ', ' after', false );
    718718                $this->assertEquals( '', ob_get_clean() );
    719719        }
     720
     721        /**
     722         * @ticket 22225
     723         */
     724        function test_date_i18n_ordinal_suffix() {
     725                $wp_locale = new WP_Locale();
     726                $this->assertEquals( 'st', $wp_locale->get_month_ordinal( 1 ) );
     727                $this->assertEquals( 'nd', $wp_locale->get_month_ordinal( '02' ) );
     728                $this->assertEquals( 'rt', $wp_locale->get_month_ordinal( '3' ) );
     729                $this->assertEquals( 'th', $wp_locale->get_month_ordinal( 12 ) );
     730
     731                /**
     732                 * Timestamp for 2015-01-15 12:00:00 == 1420113600
     733                 */
     734                $this->assertEquals( 'st', date_i18n( 'S', 1420113600 ) );
     735
     736                /**
     737                 * Timestamp for 2015-02-15 12:00:00 == 1424001600
     738                 */
     739                $this->assertEquals( 'nd', date_i18n( 'S', 1424001600 ) );
     740
     741                /**
     742                 * Timestamp for 2015-03-15 12:00:00 == 1426420800
     743                 */
     744                $this->assertEquals( 'rt', date_i18n( 'S', 1426420800 ) );
     745
     746                /**
     747                 * Timestamp for 2015-11-15 12:00:00 == 1447588800
     748                 */
     749                $this->assertEquals( 'th', date_i18n( 'S', 1447588800 ) );
     750        }
     751
    720752}
  • src/wp-includes/locale.php

     
    166166                $this->month_genitive['11'] = /* translators: month name, genitive */ _x( 'November', 'genitive' );
    167167                $this->month_genitive['12'] = /* translators: month name, genitive */ _x( 'December', 'genitive' );
    168168
     169                // The Months, ordinal
     170                $this->month_ordinal['01'] = /* translators: month name, ordinal */ _x( 'st', 'January ordinal suffix' );
     171                $this->month_ordinal['02'] = /* translators: month name, ordinal */ _x( 'nd', 'February ordinal suffix' );
     172                $this->month_ordinal['03'] = /* translators: month name, ordinal */ _x( 'rt', 'March ordinal suffix' );
     173                $this->month_ordinal['04'] = /* translators: month name, ordinal */ _x( 'th', 'April ordinal suffix' );
     174                $this->month_ordinal['05'] = /* translators: month name, ordinal */ _x( 'th', 'May ordinal suffix' );
     175                $this->month_ordinal['06'] = /* translators: month name, ordinal */ _x( 'th', 'June ordinal suffix' );
     176                $this->month_ordinal['07'] = /* translators: month name, ordinal */ _x( 'th', 'July ordinal suffix' );
     177                $this->month_ordinal['08'] = /* translators: month name, ordinal */ _x( 'th', 'August ordinal suffix' );
     178                $this->month_ordinal['09'] = /* translators: month name, ordinal */ _x( 'th', 'September ordinal suffix' );
     179                $this->month_ordinal['10'] = /* translators: month name, ordinal */ _x( 'th', 'October ordinal suffix' );
     180                $this->month_ordinal['11'] = /* translators: month name, ordinal */ _x( 'th', 'November ordinal suffix' );
     181                $this->month_ordinal['12'] = /* translators: month name, ordinal */ _x( 'th', 'October ordinal suffix' );
     182
    169183                // Abbreviations for each month.
    170184                $this->month_abbrev[ __( 'January' ) ]   = /* translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' );
    171185                $this->month_abbrev[ __( 'February' ) ]  = /* translators: three-letter abbreviation of the month */ _x( 'Feb', 'February abbreviation' );
     
    307321        }
    308322
    309323        /**
     324         * Retrieve the English ordinal suffix for the day of the month
     325         * @param string|int $month_number '01' through '12'
     326         *
     327         * @return string
     328         */
     329        public function get_month_ordinal( $month_number ) {
     330                return $this->month_ordinal[ zeroise( $month_number, 2 ) ];
     331        }
     332
     333        /**
    310334         * Retrieve translated version of meridiem string.
    311335         *
    312336         * The $meridiem parameter is expected to not be translated.