Format last modified and creation date label placeholders using the correct timezone.

Fixes issue #54
This commit is contained in:
Jan Böhmer 2020-05-13 20:12:51 +02:00
parent 5302087eba
commit 7b108f8d4b
3 changed files with 6 additions and 6 deletions

View file

@ -32,12 +32,14 @@ final class TimestampableElementProvider implements PlaceholderProviderInterface
public function replace(string $placeholder, object $label_target, array $options = []): ?string
{
if ($label_target instanceof TimeStampableInterface) {
$formatter = new IntlDateFormatter(Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
if ('[[LAST_MODIFIED]]' === $placeholder) {
return IntlDateFormatter::formatObject($label_target->getLastModified() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
return $formatter->format($label_target->getLastModified() ?? new \DateTime());
}
if ('[[CREATION_DATE]]' === $placeholder) {
return IntlDateFormatter::formatObject($label_target->getAddedDate() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
return $formatter->format($label_target->getAddedDate() ?? new \DateTime());
}
}