public function testParse() { // ARRANGE $formater = new DateFormatter(); // ACT - ASSERT $date = $formater->parse('1 Novembre 2009', 'fr'); $this->assertEquals('1 novembre 2009', $formater->format($date, 'long', 'none', 'fr')); // ACT - ASSERT $date = $formater->parse('1 Nov. 2009', 'fr'); $this->assertEquals('1 novembre 2009', $formater->format($date, 'long', 'none', 'fr')); // ACT - ASSERT $date = $formater->parse('1 Nov. 2009 10:00', 'fr'); $this->assertEquals('1 novembre 2009 10:00', $formater->format($date, 'long', 'short', 'fr')); // ACT - ASSERT $date = $formater->parse('Novembre 2009', 'fr'); $this->assertEquals('1 novembre 2009', $formater->format($date, 'long', 'none', 'fr')); // ACT - ASSERT $date = $formater->parse('Nov. 2009', 'fr'); $this->assertEquals('1 novembre 2009', $formater->format($date, 'long', 'none', 'fr')); // ACT - ASSERT $date = $formater->parse('December 2009', 'en'); $this->assertEquals('December 1, 2009', $formater->format($date, 'long', 'none', 'en')); }
/** * Translate a timestamp to a localized string representation. * Parameters dateType and timeType defines a kind of format. Allowed values are (none|short|medium|long|full). * Default is medium for the date and no time. * Uses default system locale by default. Pass another locale string to force a different translation. * You might not like the default formats, so you can pass a custom pattern as last argument. * * @param mixed $date * @param string $dateType * @param string $timeType * @param mixed $locale * @param string $pattern * * @return string The string representation */ public static function localeDateFilter($date, $dateType = 'medium', $timeType = 'none', $locale = null, $pattern = null) { $formatter = new DateFormatter(); return $formatter->format($date, $dateType, $timeType, $locale, $pattern); }