Skip to content

Commit

Permalink
Fixes #1783 - wrap IntlDateFormatter calls (fail when locale is incor…
Browse files Browse the repository at this point in the history
…rect)
  • Loading branch information
mrook committed Jan 30, 2024
1 parent 8953b2e commit c764f7f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Phing/Task/System/TstampTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
namespace Phing\Task\System;

use DateTime;
use Error;
use Exception;
use IntlDateFormatter;
use Phing\Exception\BuildException;
use Phing\Project;
use Phing\Task;

/**
Expand Down Expand Up @@ -99,7 +101,12 @@ public function main(): void
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);
$value = $formatter->format($unixTimestamp);
try {
$value = $formatter->format($unixTimestamp);
} catch (Error $e) {
$value = "";
$this->log("Unable to format date (locale $locale) [{$e->getMessage()}]", Project::MSG_WARN);
}
$this->getProject()->setNewProperty($this->prefix . $propertyName, $value);
}

Expand Down

0 comments on commit c764f7f

Please sign in to comment.