Make WordPress Core


Ignore:
Timestamp:
07/04/2018 11:42:59 PM (6 years ago)
Author:
flixos90
Message:

Date/Time: Fix usage of $gmt parameter in date_i18n() and clarify its behavior.

The docs for date_i18n() and its filter now correctly state that the $gmt parameter is only taken into account if no timestamp is provided. Furthermore, a bug with that parameter is fixed, as it is now ensured that the timezone used with it is UTC.

Props Rarst.
Fixes #38771.

File:
1 edited

Legend:

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

    r43387 r43389  
    8989 * @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset in seconds.
    9090 *                                        Default false.
    91  * @param bool     $gmt                   Optional. Whether to use GMT timezone. Default false.
     91 * @param bool     $gmt                   Optional. Whether to use GMT timezone. Only applies if timestamp is
     92 *                                        not provided. Default false.
    9293 *
    9394 * @return string The date, translated if locale specifies it.
     
    128129    if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
    129130        $timezone_string = get_option( 'timezone_string' );
     131        if ( false === $timestamp_with_offset && $gmt ) {
     132            $timezone_string = 'UTC';
     133        }
    130134        if ( $timezone_string ) {
    131135            $timezone_object = timezone_open( $timezone_string );
     
    181185     * @param string $req_format Format to display the date.
    182186     * @param int    $i          A sum of Unix timestamp and timezone offset in seconds.
    183      * @param bool   $gmt        Whether to convert to GMT for time. Default false.
     187     * @param bool   $gmt        Whether to use GMT timezone. Only applies if timestamp was
     188     *                           not provided. Default false.
    184189     */
    185190    $j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
Note: See TracChangeset for help on using the changeset viewer.