PHP fails with Uncaught IntlException: datefmt_create: No such time zone: 'Europe/Amsterdam'

I am trying to 'fix' bandwidthd-php on my OpenWRT router. I am running OpenWrt 22.03.3 r20028-43d71ad93e / LuCI openwrt-22.03 branch git-23.069.50944-cd8bea9 on x86/64.
I have installed: bandwidthd-php, php8, php8-cgi, php8-cli, php8-mod-gd, php8-mod-intl, php8-mod-pgsql, zoneinfo-*

PHP gives many warnings and errors when executing the scripts. I am resolving them by improving the PHP code and replacing obsolete functions by better implementation.

One of these is using (either of):

    //$formatter = new IntlDateFormatter('en_US', IntlDateFormatter::FULL, IntlDateFormatter::NONE,
    //                                                                 'Europe/Amsterdam', IntlDateFormatter::GREGORIAN);
    $formatter = new IntlDateFormatter('en_US', IntlDateFormatter::FULL, IntlDateFormatter::NONE);
    return $formatter->format($tm);

When I execute php-cgi debug_graph.php
(I created this file to set the url parameters for graph.php and call that file)
(in graph.php I use IntlDateFormatter)
I get the error:

Fatal error: Uncaught IntlException: datefmt_create: No such time zone: 'Europe/Amsterdam': U_ILLEGAL_ARGUMENT_ERROR in /www/bwd/graph.php:88
Stack trace:
#0 /www/bwd/graph.php(88): IntlDateFormatter->__construct('en_US', 0, -1)
#1 /www/bwd/graph.php(331): FmtTime(1680040800)
#2 /www/bwd/debug_graph.php(10): include('/www/bwd/graph....')

Running the same script on a windows or ubuntu system with php8 works fine. I do have the zoneinfo-* packages installed. What can be missing?

I suspect that OpenWrt's PHP may be built without the timezonedb? Try this and see what you get (my example is run with PHP 7.4 on Ubuntu, I don't have PHP installed on OpenWrt).

$ php -r 'echo date_default_timezone_get(), "\n";'

$ php -r 'echo date_default_timezone_set("Europe/Amsterdam"), "\n";'

From looking at, it seems like the timezones are all built into the php binary (see note at bottom about PECL's timezonedb).

Для корректной работы IntlDateFormatter нужно поставить php8-mod-intl, icu и icu-full-data.
For IntlDateFormatter to work correctly, you need to install php8-mod-intl, icu and icu-full-data.

1 Like