WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/26/2019 12:11:37 AM (16 months ago)
Author:
SergeyBiryukov
Message:

Date/Time: Replace all instances of date() with gmdate().

Use of date() in core depends on PHP timezone set to UTC and not changed by third party code (which cannot be guaranteed).

gmdate() is functionally equivalent, but is not affected by PHP timezone setting: it's always UTC, which is the exact behavior the core needs.

Props nielsdeblaauw, Rarst.
Fixes #46438. See #44491.

File:
1 edited

Legend:

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

    r45375 r45424  
    4242        return date_i18n( $format, $i );
    4343    } else {
    44         return date( $format, $i );
     44        return gmdate( $format, $i );
    4545    }
    4646}
     
    112112
    113113    if ( ( ! empty( $wp_locale->month ) ) && ( ! empty( $wp_locale->weekday ) ) ) {
    114         $datemonth            = $wp_locale->get_month( date( 'm', $i ) );
     114        $datemonth            = $wp_locale->get_month( gmdate( 'm', $i ) );
    115115        $datemonth_abbrev     = $wp_locale->get_month_abbrev( $datemonth );
    116         $dateweekday          = $wp_locale->get_weekday( date( 'w', $i ) );
     116        $dateweekday          = $wp_locale->get_weekday( gmdate( 'w', $i ) );
    117117        $dateweekday_abbrev   = $wp_locale->get_weekday_abbrev( $dateweekday );
    118         $datemeridiem         = $wp_locale->get_meridiem( date( 'a', $i ) );
    119         $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
     118        $datemeridiem         = $wp_locale->get_meridiem( gmdate( 'a', $i ) );
     119        $datemeridiem_capital = $wp_locale->get_meridiem( gmdate( 'A', $i ) );
    120120        $dateformatstring     = ' ' . $dateformatstring;
    121121        $dateformatstring     = preg_replace( '/([^\\\])D/', "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
     
    178178        }
    179179    }
    180     $j = @date( $dateformatstring, $i );
     180    $j = @gmdate( $dateformatstring, $i );
    181181
    182182    /**
     
    416416
    417417    // The day of the week from the timestamp.
    418     $weekday = date( 'w', $day );
     418    $weekday = gmdate( 'w', $day );
    419419
    420420    if ( ! is_numeric( $start_of_week ) ) {
Note: See TracChangeset for help on using the changeset viewer.