From a49a5f55a42a9eef8b8604353f5b0339afd283df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 10 Dec 2023 11:22:15 +0100 Subject: [PATCH 1/3] Fix format_date with "x" format for Windows --- program/include/rcmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 8a8cb323296..31f5bc85818 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -1698,7 +1698,7 @@ public function format_date($date, $format = null, $convert = true) $out .= $this->gettext('long'.strtolower(date('M', $timestamp))); } else if ($format[$i] == 'x') { - $formatter = new IntlDateFormatter(setlocale(LC_ALL, '0'), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); + $formatter = new IntlDateFormatter('en_US', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $out .= $formatter->format($timestamp); } else { From 191791a87cf4c92cc55356af15afb9ecf90c0758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 10 Dec 2023 12:00:56 +0100 Subject: [PATCH 2/3] set default Intl locale and use it --- program/include/rcmail.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 31f5bc85818..38b94d8312c 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -212,6 +212,7 @@ public function set_user($user) // set localization setlocale(LC_ALL, $lang . '.utf8', $lang . '.UTF-8', 'en_US.utf8', 'en_US.UTF-8'); + ini_set('intl.default_locale', $lang); // Workaround for http://bugs.php.net/bug.php?id=18556 // Also strtoupper/strtolower and other methods are locale-aware @@ -1698,7 +1699,7 @@ public function format_date($date, $format = null, $convert = true) $out .= $this->gettext('long'.strtolower(date('M', $timestamp))); } else if ($format[$i] == 'x') { - $formatter = new IntlDateFormatter('en_US', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); + $formatter = new IntlDateFormatter(null, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); $out .= $formatter->format($timestamp); } else { From aef433e0b05d4eb83bf922a8104ae8cf8c44bf7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 10 Dec 2023 15:29:14 +0100 Subject: [PATCH 3/3] harden default test config --- tests/Rcmail/Rcmail.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Rcmail/Rcmail.php b/tests/Rcmail/Rcmail.php index 4a16b38d40c..e6b1dc861d6 100644 --- a/tests/Rcmail/Rcmail.php +++ b/tests/Rcmail/Rcmail.php @@ -272,6 +272,7 @@ function test_format_date() // Test various formats setlocale(LC_ALL, 'en_US'); + ini_set('intl.default_locale', 'en_US'); $date = new DateTime('2020-06-01 12:20:30', new DateTimeZone('UTC')); $this->assertSame('2020-06-01 12:20', $rcmail->format_date($date));