2

I've been struggling with a weird problem today. For some reason my server pretends that the timezone 'Europe/Berlin' is UTC (it should be UTC+1). If I set the timezone to 'Europe/Brussels' for example, it converts the time correctly.

I've created some dummy code to test my server and on an online compiler. While the compiler works (I've used http://sandbox.onlinephpfunctions.com/), my server persists to have this issue.

Here's the code:

<?php
$time = 'now';

$timezone1 = 'Europe/London';
$timezone2 = 'Europe/Berlin';
$timezone3 = date_default_timezone_get();
$timezone4 = 'Europe/Brussels';

$dateTime1 = new \DateTime($time, new DateTimeZone($timezone1));
$timeParsed1 = $dateTime1->format('Y-m-d H:i:sP');

$dateTime2 = new \DateTime($time, new DateTimeZone($timezone2));
$timeParsed2 = $dateTime2->format('Y-m-d H:i:sP');

$dateTime3 = new \DateTime($time, new DateTimeZone($timezone3));
$timeParsed3 = $dateTime3->format('Y-m-d H:i:sP');

$dateTime4 = new \DateTime($time, new DateTimeZone($timezone4));
$timeParsed4 = $dateTime4->format('Y-m-d H:i:sP');

echo($timezone1 . ': ' . $timeParsed1 . '<br>' . $timezone2 . ': ' . $timeParsed2 . '<br>' . $timezone3 . ': ' . $timeParsed3 . '<br>' . $timezone4 . ': ' . $timeParsed4);
?>

And here's the output that this genereates:

Europe/London: 2017-01-26 01:24:18+00:00
Europe/Berlin: 2017-01-26 01:24:18+00:00
UTC: 2017-01-26 01:24:18+00:00
Europe/Brussels: 2017-01-26 02:24:18+01:00

I've been trying to find the cause for this and searched here on Stackoverflow, but I couldn't find the reason. Here's a link to my phpinfo(): http://arma.jianji.de/phpinfo.php

And this is the dummy code on my server in action: http://arma.jianji.de/phptest.php

The server has been recently set up by me using Ubtuntu 16 LTS and Plesk Onyx. The server default timezone is set to London.

Unfortunately, I've been unable to find the reason for this. Do you have an idea?

Thank you in advance for your help!

Update

Because this has been brought up quite a lot, I've created a test where I set a default timezone by using:

date_default_timezone_set('Europe/Brussels');

Additionally, I've added "Europe/London" as default timezone in my php.ini.

The issue still persists: http://arma.jianji.de/phptest_default.php

jastend
  • 1,529
  • 1
  • 8
  • 17
  • What version of PHP is the server running? – ceejayoz Jan 26 '17 at 01:42
  • I've attached the phpinfo so you can check all details, but it's "PHP Version 7.0.13-0ubuntu0.16.04.1" – jastend Jan 26 '17 at 01:43
  • As far as i understand you are not able to set the different time zone. If this is a case then please try the date_default_timezone_set function you can get it's details at http://php.net/manual/en/function.date-default-timezone-set.php – Abbas Jan 26 '17 at 01:46
  • @Abbas I don't think you read the question. – ceejayoz Jan 26 '17 at 01:50
  • Hi @Abbas, Not exactly. I can set any timezone other than Europe/Berlin. So for example Europe/Brussels, which is UTC+1 like Europe/Berlin works. In order to make sure, I've added Europe/London as default timezone but the issue persists. Here's the output: Europe/London: 2017-01-26 01:50:30+00:00 Europe/Berlin: 2017-01-26 01:50:30+00:00 Europe/London: 2017-01-26 01:50:30+00:00 Europe/Brussels: 2017-01-26 02:50:30+01:00 – jastend Jan 26 '17 at 01:51
  • 1
    If I'm understanding the issue correctly, this seems to be a bug in PHP 7s time zone definitions. Brussels and Berlin are both in UTC+01:00 ... https://bugs.php.net/ – Duane Lortie Jan 26 '17 at 01:59
  • 1
    Is your `tzdata` package up to date? You can simulate a package update with `apt-get -s install tzdata` – Scopey Jan 26 '17 at 02:19
  • @Scopey Yes, I get: tzdata is already the newest version (2016j-0ubuntu0.16.04). – jastend Jan 26 '17 at 02:20
  • 1
    @jastend, what is the output of `date +%z` command? – Ruslan Osmanov Jan 26 '17 at 02:37
  • @RuslanOsmanov It's 0 for London and Berlin and 3600 for Brussels. – jastend Jan 26 '17 at 03:08
  • 2
    @jastend, there should be something wrong with tzdata. Check out the output of `zdump -V Europe/Berlin | grep 2017`. I'd recommend updating the timezone-data package and reinstalling PHP – Ruslan Osmanov Jan 26 '17 at 03:14
  • @RuslanOsmanov I think you are right. The output shows this: $ zdump -V Europe/Berlin | grep 2017 Europe/Berlin Sun Mar 26 00:59:59 2017 UT = Sun Mar 26 00:59:59 2017 GMT isdst=0 gmtoff=0 Europe/Berlin Sun Mar 26 01:00:00 2017 UT = Sun Mar 26 02:00:00 2017 BST isdst=1 gmtoff=3600 Europe/Berlin Sun Oct 29 00:59:59 2017 UT = Sun Oct 29 01:59:59 2017 BST isdst=1 gmtoff=3600 Europe/Berlin Sun Oct 29 01:00:00 2017 UT = Sun Oct 29 01:00:00 2017 GMT isdst=0 gmtoff=0 – jastend Jan 26 '17 at 03:21

1 Answers1

2

As @RuslanOsmanov kindly pointed out, the timezone data for Europe/Berlin was incorrect. I was able to verify this by using

zdump -V Europe/Berlin | grep 2017

In order to fix this, I performed a reinstall of tzdata which fixed the problem.

 apt-get --reinstall install tzdata
jastend
  • 1,529
  • 1
  • 8
  • 17