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.

Built from https://develop.svn.wordpress.org/trunk@43389


git-svn-id: http://core.svn.wordpress.org/trunk@43217 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2018-07-04 23:43:25 +00:00
parent 057b221af7
commit 46589d1578
2 changed files with 8 additions and 3 deletions

View File

@ -88,7 +88,8 @@ function current_time( $type, $gmt = 0 ) {
* @param string $dateformatstring Format to display the date.
* @param int|bool $timestamp_with_offset Optional. A sum of Unix timestamp and timezone offset in seconds.
* Default false.
* @param bool $gmt Optional. Whether to use GMT timezone. Default false.
* @param bool $gmt Optional. Whether to use GMT timezone. Only applies if timestamp is
* not provided. Default false.
*
* @return string The date, translated if locale specifies it.
*/
@ -127,6 +128,9 @@ function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa
$timezone_formats_re = implode( '|', $timezone_formats );
if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
$timezone_string = get_option( 'timezone_string' );
if ( false === $timestamp_with_offset && $gmt ) {
$timezone_string = 'UTC';
}
if ( $timezone_string ) {
$timezone_object = timezone_open( $timezone_string );
$date_object = date_create( null, $timezone_object );
@ -180,7 +184,8 @@ function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa
* @param string $j Formatted date string.
* @param string $req_format Format to display the date.
* @param int $i A sum of Unix timestamp and timezone offset in seconds.
* @param bool $gmt Whether to convert to GMT for time. Default false.
* @param bool $gmt Whether to use GMT timezone. Only applies if timestamp was
* not provided. Default false.
*/
$j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
return $j;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43388';
$wp_version = '5.0-alpha-43389';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.