diff --git a/src/DataTables/Column/LocaleDateTimeColumn.php b/src/DataTables/Column/LocaleDateTimeColumn.php new file mode 100644 index 00000000..487a1343 --- /dev/null +++ b/src/DataTables/Column/LocaleDateTimeColumn.php @@ -0,0 +1,93 @@ +options['nullValue']; + } elseif (!$value instanceof \DateTimeInterface) { + $value = new \DateTime((string) $value); + } + + $formatValues = array( + 'none' => IntlDateFormatter::NONE, + 'short' => IntlDateFormatter::SHORT, + 'medium' => IntlDateFormatter::MEDIUM, + 'long' => IntlDateFormatter::LONG, + 'full' => IntlDateFormatter::FULL, + ); + + $formatter = IntlDateFormatter::create( + \Locale::getDefault(), + $formatValues[$this->options['dateFormat']], + $formatValues[$this->options['timeFormat']], + $value->getTimezone() + ); + + return $formatter->format($value->getTimestamp()); + } + + /** + * {@inheritdoc} + */ + protected function configureOptions(OptionsResolver $resolver) + { + parent::configureOptions($resolver); + + $resolver + ->setDefaults([ + 'dateFormat' => 'short', + 'timeFormat' => 'short', + 'nullValue' => '' + ]) + ->setAllowedTypes('nullValue', 'string') + ; + + return $this; + } +} \ No newline at end of file diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index 0edd0aa2..c2167153 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -29,6 +29,7 @@ namespace App\DataTables; +use App\DataTables\Column\LocaleDateTimeColumn; use App\Entity\Parts\Category; use App\Entity\Parts\Part; use App\Services\EntityURLGenerator; @@ -115,11 +116,11 @@ class PartsDataTable implements DataTableTypeInterface ]) //->add('storelocation', TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label']) - ->add('addedDate', DateTimeColumn::class, [ + ->add('addedDate', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('part.table.addedDate'), 'visible' => false ]) - ->add('lastModified', DateTimeColumn::class, [ + ->add('lastModified', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('part.table.lastModified'), 'visible' => false ])