mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 19:34:31 +02:00
Format last modified and creation date label placeholders using the correct timezone.
Fixes issue #54
This commit is contained in:
parent
5302087eba
commit
7b108f8d4b
3 changed files with 6 additions and 6 deletions
|
@ -63,7 +63,6 @@ final class PartLotProvider implements PlaceholderProviderInterface
|
||||||
Locale::getDefault(),
|
Locale::getDefault(),
|
||||||
IntlDateFormatter::SHORT,
|
IntlDateFormatter::SHORT,
|
||||||
IntlDateFormatter::NONE
|
IntlDateFormatter::NONE
|
||||||
//$label_target->getExpirationDate()->getTimezone()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $formatter->format($label_target->getExpirationDate());
|
return $formatter->format($label_target->getExpirationDate());
|
||||||
|
|
|
@ -32,12 +32,14 @@ final class TimestampableElementProvider implements PlaceholderProviderInterface
|
||||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||||
{
|
{
|
||||||
if ($label_target instanceof TimeStampableInterface) {
|
if ($label_target instanceof TimeStampableInterface) {
|
||||||
|
$formatter = new IntlDateFormatter(Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
|
||||||
|
|
||||||
if ('[[LAST_MODIFIED]]' === $placeholder) {
|
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) {
|
if ('[[CREATION_DATE]]' === $placeholder) {
|
||||||
return IntlDateFormatter::formatObject($label_target->getAddedDate() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
|
return $formatter->format($label_target->getAddedDate() ?? new \DateTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,10 @@ class TimestampableElementProviderTest extends WebTestCase
|
||||||
public function dataProvider(): array
|
public function dataProvider(): array
|
||||||
{
|
{
|
||||||
\Locale::setDefault('en');
|
\Locale::setDefault('en');
|
||||||
$formatted = \IntlDateFormatter::formatObject(new \DateTime('2000-01-01'), \IntlDateFormatter::SHORT);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[$formatted, '[[LAST_MODIFIED]]'],
|
['1/1/00, 12:00 AM', '[[LAST_MODIFIED]]'],
|
||||||
[$formatted, '[[CREATION_DATE]]'],
|
['1/1/00, 12:00 AM', '[[CREATION_DATE]]'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue