Bug #79863 [Com]: Timezone conversion result depends on environment
Edit report at https://bugs.php.net/bug.php?id=79863&edit=1
ID: 79863
Comment by: antonino dot spampinato86 at gmail dot com
Reported by: bassjoe at web dot de
Summary: Timezone conversion result depends on environment
Status: Open
Type: Bug
Package: Date/time related
Operating System: CentOS Linux 7
PHP Version: 7.4.8
Block user comment: N
Private report: N
New Comment:
<?php
$datetime = date_create("2020-07-13 10:38:15", timezone_open("Europe/Berlin"));
date_timezone_set( $datetime, timezone_open( "UTC" ) ); date_format( $datetime,
"Y-m-d H:i:s" ); var_dump($datetime);
Expected result:
----------------
object(DateTime)#5 (3) {
["date"]=>
string(26) "2020-07-13 08:38:15.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
timezone now is UTC?
Previous Comments:
------------------------------------------------------------------------
[2020-07-15 09:22:20] bassjoe at web dot de
wp_timezone()->getName() is what I logged and it was "Europe/Berlin"
------------------------------------------------------------------------
[2020-07-15 09:17:27] bassjoe at web dot de
"Europe/Berlin"
------------------------------------------------------------------------
[2020-07-15 09:10:22] requinix@php.net
What is the value being returned by wp_timezone()?
------------------------------------------------------------------------
[2020-07-15 09:01:49] bassjoe at web dot de
Description:
------------
WordPress uses (in wp-includes/formatting.php) the following PHP function calls to convert Date/Time
objects to a different timezone (simplified):
function get_gmt_from_date( $string ) {
$datetime = date_create( $string, wp_timezone() );
return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format(
'Y-m-d H:i:s' );
}
This fails on my Strato/CentOS7 Server (PHP 7.4.8) because get_gmt_from_date() returns the same
value that is given as $string argument. I can easily reproduce this with the following command on
the console:
php -r '$datetime = date_create("2020-07-13 10:38:15", new
DateTimeZone("Europe/Berlin")); echo $datetime->setTimezone( new DateTimeZone(
"UTC" ) )->format( "Y-m-d H:i:s\n" );'
2020-07-13 10:38:15
On my Fedora 31 workstation (also PHP 7.4.8) the same command returns the correct result:
2020-07-13 08:38:15
I installed CentOS 7 on a VM but could not reproduce the error. This means the result of these PHP
functions depends on the server configuration.
The result of a timezone conversion obviously should not depend on the environment.
The effect I have noticed in WordPress is that changes in the Customizer can't be published
immediately.
Test script:
---------------
php -r '$datetime = date_create("2020-07-13 10:38:15", new
DateTimeZone("Europe/Berlin")); echo $datetime->setTimezone( new DateTimeZone(
"UTC" ) )->format( "Y-m-d H:i:s\n" );'
Expected result:
----------------
2020-07-13 08:38:15
Actual result:
--------------
2020-07-13 10:38:15
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79863&edit=1
Thread (10 messages)