mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-22 23:41:38 +01:00
Date/Time: Add support for gmt_offset
to date_i18n()
.
Prior to this change, `date_i18n()` only supported the `timezone_string` option, causing incorrect timezones to appear in formatted dates on sites that still rely on the `gmt_offset` option. Props Rarst. Fixes #34835. Built from https://develop.svn.wordpress.org/trunk@43387 git-svn-id: http://core.svn.wordpress.org/trunk@43215 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b76a714bba
commit
dc036d5333
@ -138,6 +138,36 @@ function date_i18n( $dateformatstring, $timestamp_with_offset = false, $gmt = fa
|
||||
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) - 1 );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$offset = get_option( 'gmt_offset' );
|
||||
foreach ( $timezone_formats as $timezone_format ) {
|
||||
if ( 'I' === $timezone_format ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
|
||||
if ( 'Z' === $timezone_format ) {
|
||||
$formatted = (string) ( $offset * HOUR_IN_SECONDS );
|
||||
} else {
|
||||
$prefix = '';
|
||||
$hours = (int) $offset;
|
||||
$separator = '';
|
||||
$minutes = abs( ( $offset - $hours ) * 60 );
|
||||
|
||||
if ( 'T' === $timezone_format ) {
|
||||
$prefix = 'GMT';
|
||||
} elseif ( 'e' === $timezone_format || 'P' === $timezone_format ) {
|
||||
$separator = ':';
|
||||
}
|
||||
|
||||
$formatted = sprintf( '%s%+03d%s%02d', $prefix, $hours, $separator, $minutes );
|
||||
}
|
||||
|
||||
$dateformatstring = ' ' . $dateformatstring;
|
||||
$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
|
||||
$dateformatstring = substr( $dateformatstring, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$j = @date( $dateformatstring, $i );
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.0-alpha-43386';
|
||||
$wp_version = '5.0-alpha-43387';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user