1

I am trying to fix a timezone issue in a PHP 8.2 web application. Any date before 1940-02-25 has a one-day difference when comparing the production server (Debian 12) to my local development machine (Fedora 38). Both machines have PHP 8.2, the "Olson" Timezone Database version 2023.3 and PHP's timezone set to 'Europe/Amsterdam'. But the production server behaves differently.

Below is a straight forward example of three dates: one before, one on and one after the 1940-02-25. I know there was a timezone-related event in Great Britain, but why should that affect the Amterdam timezone?

Curious: if I alter the timezone to 'Europe/London', both systems behave the same.

For comparison, I added a \DateTime->format() for each date, too. They are correct on both systems.

$locale = 'nl_NL';
$tz = new \DateTimeZone('Europe/Amsterdam');
$dtfmt = new \IntlDateFormatter(
    $locale, \IntlDateFormatter::NONE, \IntlDateFormatter::NONE,
    $tz, \IntlDateFormatter::GREGORIAN, "E dd-MM-y"
);

$dt = new \DateTime('1940-02-24', $tz);
print '1940-02-24 => '. $dt->format('   d-m-Y').PHP_EOL;
print '1940-02-24 => '. $dtfmt->format($dt).PHP_EOL;
print PHP_EOL;

$dt = new \DateTime('1940-02-25', $tz);
print '1940-02-25 => '. $dt->format('   d-m-Y').PHP_EOL;
print '1940-02-25 => '. $dtfmt->format($dt).PHP_EOL;
print PHP_EOL;

$dt = new \DateTime('1940-02-26', $tz);
print '1940-02-26 => '. $dt->format('   d-m-Y').PHP_EOL;
print '1940-02-26 => '. $dtfmt->format($dt).PHP_EOL;
print PHP_EOL;

Expected output (and actual output on my local machine):

1940-02-24 =>    24-02-1940
1940-02-24 => za 24-02-1940

1940-02-25 =>    25-02-1940
1940-02-25 => zo 25-02-1940

1940-02-26 =>    26-02-1940
1940-02-26 => ma 26-02-1940

Instead, I get this on the production server:

1940-02-24 =>    24-02-1940
1940-02-24 => vr 23-02-1940

1940-02-25 =>    25-02-1940
1940-02-25 => za 24-02-1940

1940-02-26 =>    26-02-1940
1940-02-26 => ma 26-02-1940

How can I fix this discrepancy?

Thanks and kind regards,
Frans-Willem

  • I'm not able to reproduce this. What versions of PHP are on each system and what are the default timezones (`date_default_timezone_get()`) ? – Jim Aug 23 '23 at 12:36
  • I also would say your server has a different timezone config than your local system. – Markus Zeller Aug 23 '23 at 14:29
  • @Jim , the local development machine runs PHP 8.2.9 on Fedora 38 with `\IntlTimeZone::getTZDataVersion()` being `2022e`. The production server runs PHP 8.2.8 on Debian 12 with `\IntlTimeZone::getTZDataVersion()` being `2022e`, too. Both systems have `date_default_timezone_get()` being `UTC`. – Frans-Willem Post Aug 23 '23 at 20:48
  • @MarkusZeller both systems have their timezone set to `Europe/Amsterdam` on a system level. In both PHP's, `date_default_timezone_get()` returns `UTC`, see my previous comment to Jim. – Frans-Willem Post Aug 23 '23 at 20:52
  • 1
    @Frans-WillemPost apparently this is a bug (or maybe not?) in the newer ICU library versions which are used on some systems including Debian: https://github.com/php/php-src/issues/10898 | Try the workaround suggested, use `IntlDateFormatter::formatObject()` instead of `format()` (the latter drops the date object's timezone and uses the INTL default and formatter timezones instead which might be the issue). – Jim Aug 23 '23 at 22:31
  • Maybe there is still something configured different. You could check a diff of both php -i. Also note, that php-cli and php-fpm may have also different configs. – Markus Zeller Aug 24 '23 at 09:57
  • @MarkusZeller The only relevant difference I can find from both `php -i`: Local development machine: `timelib version => 2022.09` and Server: `timelib version => 2022.07`. The Olson database versions are the same, though. – Frans-Willem Post Aug 28 '23 at 19:34

0 Answers0