WordPress.org

Make WordPress Core

Changeset 10408


Ignore:
Timestamp:
01/22/2009 09:05:55 PM (9 years ago)
Author:
westi
Message:

Reduce code in mysql2date. Fixes #8166 props jacobsantos

File:
1 edited

Legend:

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

    r10353 r10408  
    3030
    3131    if( 'G' == $dateformatstring ) {
    32         return gmmktime(
    33             (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
    34             (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
    35         );
    36     }
    37 
    38     $i = mktime(
    39         (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
    40         (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
    41     );
     32        return strtotime( $m . ' +0000' );
     33    }
     34
     35    $i = strtotime( $m );
    4236
    4337    if( 'U' == $dateformatstring )
    4438        return $i;
    4539
    46     if ( -1 == $i || false == $i )
    47         $i = 0;
    48 
    49     if ( !empty( $wp_locale->month ) && !empty( $wp_locale->weekday ) && $translate ) {
    50         $datemonth = $wp_locale->get_month( date( 'm', $i ) );
    51         $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
    52         $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
    53         $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
    54         $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
    55         $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
    56         $dateformatstring = ' ' . $dateformatstring;
    57         $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
    58         $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
    59         $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
    60         $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
    61         $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
    62         $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
    63 
    64         $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
    65     }
    66     $j = @date( $dateformatstring, $i );
    67 
    68     /*
    69     if ( !$j ) // for debug purposes
    70         echo $i." ".$mysqlstring;
    71     */
    72 
    73     return $j;
     40    return date_i18n( $dateformatstring, $i );
    7441}
    7542
     
    10976 * @since 0.71
    11077 *
    111  * @param string $dateformatstring Format to display the date
    112  * @param int $unixtimestamp Unix timestamp
     78 * @param string $dateformatstring Format to display the date.
     79 * @param int $unixtimestamp Optional. Unix timestamp.
     80 * @param bool $gmt Optional, default is false. Whether to convert to GMT for time.
    11381 * @return string The date, translated if locale specifies it.
    11482 */
Note: See TracChangeset for help on using the changeset viewer.