Make WordPress Core

Changeset 43434


Ignore:
Timestamp:
07/05/2018 11:10:01 PM (7 years ago)
Author:
johnbillion
Message:

Date/Time: Add support for the c and r shorthand formats in date_i18n().

Props Rarst, pbearne

Fixes #20973

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r43406 r43434  
    107107     */
    108108    $req_format = $dateformatstring;
     109
     110    $dateformatstring = preg_replace( "/(?<!\\\\)c/", DATE_W3C, $dateformatstring );
     111    $dateformatstring = preg_replace( "/(?<!\\\\)r/", DATE_RFC2822, $dateformatstring );
    109112
    110113    if ( ( ! empty( $wp_locale->month ) ) && ( ! empty( $wp_locale->weekday ) ) ) {
  • trunk/tests/phpunit/tests/date/dateI18n.php

    r43389 r43434  
    8484        $this->assertEquals( $datetime->format( $timezone_formats ), date_i18n( $timezone_formats ) );
    8585    }
     86
     87    /**
     88     * @dataProvider data_formats
     89     * @ticket 20973
     90     */
     91    public function test_date_i18n_handles_shorthand_formats( $short, $full ) {
     92        $this->assertEquals( date_i18n( $full ), date_i18n( $short ) );
     93        $this->assertEquals( $short, date_i18n( '\\' . $short ) );
     94    }
     95
     96    public function data_formats() {
     97        return array(
     98            array(
     99                'c',
     100                'Y-m-d\TH:i:sP',
     101            ),
     102            array(
     103                'r',
     104                'D, d M Y H:i:s O',
     105            ),
     106        );
     107    }
    86108}
Note: See TracChangeset for help on using the changeset viewer.