Make WordPress Core

Ticket #8153: proper-current-time-for-date_i18n.diff

File proper-current-time-for-date_i18n.diff, 1.8 KB (added by nbachiyski, 16 years ago)

If timestamp is missing use current time + offset and set gmt to true, so that the dates are shown properly. Also, use the right function in all places

  • wp-includes/functions.php

     
    116116        global $wp_locale;
    117117        $i = $unixtimestamp;
    118118        // Sanity check for PHP 5.1.0-
    119         if ( false === $i || intval($i) < 0 )
    120                 $i = time();
     119        if ( false === $i || intval($i) < 0 ) {
     120                $i = current_time( 'timestamp' );
     121                // we should not let date() interfere with our
     122                // specially computed timestamp
     123                $gmt = true;
     124        }
    121125
     126        $datefunc = $gmt? 'gmdate' : 'date';
     127
    122128        if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
    123                 $datemonth = $wp_locale->get_month( date( 'm', $i ) );
     129                $datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );
    124130                $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
    125                 $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
     131                $dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) );
    126132                $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
    127                 $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
    128                 $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
     133                $datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) );
     134                $datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) );
    129135                $dateformatstring = ' '.$dateformatstring;
    130136                $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
    131137                $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
     
    136142
    137143                $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
    138144        }
    139         $j = $gmt? @gmdate( $dateformatstring, $i ) : @date( $dateformatstring, $i );
     145        $j = @$datefunc( $dateformatstring, $i );
    140146        return $j;
    141147}
    142148