1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
From: William Desportes <williamdes@wdes.fr>
Date: Sun, 13 Apr 2025 15:15:59 +0200
Subject: Fix PHP 8.4 new IntlDateFormatter
8.4.0 A ValueError is thrown if locale is invalid.
Origin: vendor
Forwarded: no
---
src/Phing/Task/System/TstampTask.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/Phing/Task/System/TstampTask.php b/src/Phing/Task/System/TstampTask.php
index c502021..8c1cb20 100644
--- a/src/Phing/Task/System/TstampTask.php
+++ b/src/Phing/Task/System/TstampTask.php
@@ -22,6 +22,7 @@ namespace Phing\Task\System;
use DateTime;
use Error;
+use ValueError;
use Exception;
use IntlDateFormatter;
use Phing\Exception\BuildException;
@@ -100,12 +101,15 @@ class TstampTask extends Task
*/
protected function createProperty(string $propertyName, int $unixTimestamp, ?string $pattern = null, ?string $locale = null, ?string $timezone = null): void
{
- $formatter = new IntlDateFormatter($locale, IntlDateFormatter::LONG, IntlDateFormatter::NONE, $timezone, IntlDateFormatter::GREGORIAN, $pattern);
try {
+ $formatter = new IntlDateFormatter($locale, IntlDateFormatter::LONG, IntlDateFormatter::NONE, $timezone, IntlDateFormatter::GREGORIAN, $pattern);
$value = $formatter->format($unixTimestamp);
} catch (Error $e) {
$value = "";
$this->log("Unable to format date (locale $locale) [{$e->getMessage()}]", Project::MSG_WARN);
+ } catch (ValueError $e) {
+ $value = "";
+ $this->log("Unable to create a date formatter (locale $locale) [{$e->getMessage()}]", Project::MSG_WARN);
}
$this->getProject()->setNewProperty($this->prefix . $propertyName, $value);
}
|