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

From: Date: Fri, 04 Dec 2020 13:46:17 +0000
Subject: Bug #79863 [Com]: Timezone conversion result depends on environment
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230843@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
 Comment by:         smeyer dot ilias at gmx dot de
 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:

I observed a similar issue with PHP 7.2.5 on SLES 12 SP 5: 

<?php

date_default_timezone_set('UTC');
echo date('Y-m-d: H:i:s e');
date_default_timezone_set('Europe/Berlin');
echo date('Y-m-d: H:i:s e');
date_default_timezone_set('Asia/Irkutsk');
echo date('Y-m-d: H:i:s e');

Returns: 
2020-12-04: 12:43:34 UTC
2020-12-04: 12:43:34 Europe/Berlin
2020-12-04: 12:43:34 Asia/Irkutsk

Changes in /etc/php/cli/php.ini date.timezone did not make difference. 
I have no direct access to the server, but could provide more information regarding the server
environment.


Previous Comments:
------------------------------------------------------------------------
[2020-07-25 20:31:17] bassjoe at web dot de

Now this is very strange.  I get the correct result if I check out PHP 7.4.8 (same version as the
REMI packages) from Git, compile it on CentOS 7, and run this php executable on the server. So in
the same environment and while ignoring php.ini (with -n) I get different results for the same
version.

# installed from remi repo:
# php-cli-7.4.8-2.el7.remi.x86_64
# php-7.4.8-2.el7.remi.x86_64

$ php --version
PHP 7.4.8 (cli) (built: Jul  9 2020 08:57:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies


$ php -n -r '$datetime = date_create("2020-07-13 10:38:15", new
DateTimeZone("Europe/Berlin")); var_dump($datetime); $datetime->setTimezone( new
DateTimeZone( "UTC" ) ); var_dump($datetime);'

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2020-07-13 10:38:15.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(13) "Europe/Berlin"
}
object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2020-07-13 10:38:15.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}


# self-compiled on centos 7 => correct result

$ sapi/cli/php --version
PHP 7.4.8 (cli) (built: Jul 25 2020 22:12:24) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies


$ sapi/cli/php -n -r '$datetime = date_create("2020-07-13 10:38:15", new
DateTimeZone("Europe/Berlin")); var_dump($datetime); $datetime->setTimezone( new
DateTimeZone( "UTC" ) ); var_dump($datetime);'

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2020-07-13 10:38:15.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(13) "Europe/Berlin"
}
object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2020-07-13 08:38:15.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}

------------------------------------------------------------------------
[2020-07-17 19:21:22] bassjoe at web dot de

The result is the same with this command sequence.

Workstation (correct):

    $ php -r '$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);'
    Command line code:1:
    class DateTime#2 (3) {
      public $date =>
      string(26) "2020-07-13 08:38:15.000000"
      public $timezone_type =>
      int(3)
      public $timezone =>
      string(3) "UTC"
    }

Server (wrong):

    $ php -r '$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);'
    object(DateTime)#2 (3) {
      ["date"]=>
      string(26) "2020-07-13 10:38:15.000000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(3) "UTC"
    }

------------------------------------------------------------------------
[2020-07-17 13:37:58] antonino dot spampinato86 at gmail dot com

<?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?

------------------------------------------------------------------------
[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"

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=79863


--
Edit this bug report at https://bugs.php.net/bug.php?id=79863&edit=1


Thread (10 messages)

« previous php.bugs (#230843) next »