/** * Handles DateTime fields * * @param DataEvent $event */ public function onDataReady(DataEvent $event) { $data = array(); foreach ($event->getData() as $key => $row) { foreach ($row as $field => $value) { if ($value instanceof \DateTime) { $formatter = \IntlDateFormatter::create($this->locale, static::$formats[$this->dateFormat], static::$formats[$this->timeFormat], $this->timezone, IntlDateFormatter::GREGORIAN, $this->format); if (!$formatter) { $formatter = IntlDateFormatter::create('en', static::$formats[$this->dateFormat], static::$formats[$this->timeFormat], $this->timezone, \IntlDateFormatter::GREGORIAN, $this->format); } $value = $formatter->format($value->getTimestamp()); } $data[$key][$field] = $value; } } $event->setData($data); }
public function testStaticCreate() { $formatter = IntlDateFormatter::create('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT); $this->assertInstanceOf('\\Symfony\\Component\\Intl\\DateFormatter\\IntlDateFormatter', $formatter); }