0

What is the reason for IntlDateFormatter returning different values for a UTC time across these different servers (see last output line from examples below)?

Server A

> php --version
PHP 7.3.6 (cli) (built: Jun 17 2019 21:27:20) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.6, Copyright (c) 1998-2018 Zend Technologies

> php -a
Interactive shell

php > $fmt = new \IntlDateFormatter('en_US', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, 'UTC', \IntlDateFormatter::GREGORIAN);
php > echo $fmt->format(new \DateTime('July 1, 2019 12:00pm'));
Monday, July 1, 2019 at 12:00:00 PM GMT

Server B

> php --version
PHP 7.3.7 (cli) (built: Jul  3 2019 22:04:27) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.7, Copyright (c) 1999-2018, by Zend Technologies

> php -a
Interactive shell

php > $fmt = new \IntlDateFormatter('en_US', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, 'UTC', \IntlDateFormatter::GREGORIAN);
php > echo $fmt->format(new \DateTime('July 1, 2019 12:00pm'));
Monday, July 1, 2019 at 12:00:00 PM Coordinated Universal Time
etipaced
  • 125
  • 1
  • 11
  • 1
    This is likely because of updates to `libicu`. Check the dependencies of the packages to find the exact version and then you can dig into the changelog. – msg Jul 21 '19 at 02:17
  • @msg I wasn't able to find the specific changelog to verify the exact issue, but at least I discovered that Server A is running libicu-dev 57.1 and Server B is running libicu-dev 60.2. This is just another instance of having 2 different environments biting me in the ass. Thank you for pointing me in the right direction. – etipaced Jul 22 '19 at 16:13
  • I might have been wrong... I [can't find](https://github.com/unicode-cldr/cldr-dates-full/blob/0bc49271d1b8eae73084dc9dc5870e05eef898ba/main/en-US-POSIX/ca-gregorian.json#L331) changes in the CLDR between versions 29 and 32. Can you check your server config? What's the default timezone in `php.ini`? – msg Jul 22 '19 at 17:04
  • Both servers show: `/etc/localtime -> /usr/share/zoneinfo/Etc/UTC`. Edit: Just realized you were asking after PHP's config. Again, however, both are showing UTC: `Default timezone => UTC date.timezone => UTC => UTC` – etipaced Jul 22 '19 at 17:11

1 Answers1

0

The servers have different default settings for the default time zones for DateTime. You have to set the same time zone for DateTime to get identical outputs. It is not enough to set the time zone only for the IntlDateFormatter.

<?php
$fmt = new \IntlDateFormatter(
  'en_US', 
  \IntlDateFormatter::FULL, 
  \IntlDateFormatter::FULL, 
  'UTC', 
  \IntlDateFormatter::GREGORIAN
);
echo $fmt->format(new \DateTime('July 1, 2019 12:00pm', new \DateTimeZone('UTC')));
jspit
  • 7,276
  • 1
  • 9
  • 17