Bug #79863 [Fbk->Opn]: Timezone conversion result depends on environment

From: Date: Wed, 15 Jul 2020 09:17:27 +0000
Subject: Bug #79863 [Fbk->Opn]: Timezone conversion result depends on environment
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228063@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79863&edit=1

 ID:                 79863
 User updated by:    bassjoe at web dot de
 Reported by:        bassjoe at web dot de
 Summary:            Timezone conversion result depends on environment
-Status:             Feedback
+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:

"Europe/Berlin"


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#228063) next »