Bug #79863 [NEW]: Timezone conversion result depends on environment

From: Date: Wed, 15 Jul 2020 09:01:49 +0000
Subject: Bug #79863 [NEW]: Timezone conversion result depends on environment
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228061@lists.php.net to get a copy of this message
From: bassjoe at web dot de Operating system: CentOS Linux 7 PHP version: 7.4.8 Package: Date/time related Bug Type: Bug Bug description:Timezone conversion result depends on environment 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 bug report at https://bugs.php.net/bug.php?id=79863&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79863&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79863&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79863&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79863&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79863&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79863&r=support Expected behavior: https://bugs.php.net/fix.php?id=79863&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79863&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79863&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79863&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79863&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79863&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79863&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79863&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79863&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79863&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79863&r=mysqlcfg

« previous php.bugs (#228061) next »