/** * @inheritDoc */ public function formatValue(string $typeSpecifier, $value) : string { $valueTypeCheck = $this->valueTypeCheck; $valueTypeCheck($value); // MessageFormatter supports IntlCalendar, but HHVM does a strange date format. if ($value instanceof IntlCalendar) { $value = $value->toDateTime(); } return Message::formatMessage($this->locale, $this->messageFormats[$typeSpecifier], [$value]); }
public function testFormatValueDateParts() { $messageFormatter = MessageFormatter::createDateValueFormatter('de_DE'); $date = new DateTime('2016-04-01'); $this->assertSame('2016', $messageFormatter->formatValue('date_year', $date)); $this->assertSame('4', $messageFormatter->formatValue('date_month', $date)); $this->assertSame('April', $messageFormatter->formatValue('date_month_name', $date)); $this->assertSame('1', $messageFormatter->formatValue('date_day', $date)); $this->assertSame('Freitag', $messageFormatter->formatValue('date_weekday', $date)); }
/** * @param string $locale * @return IntlFormat */ public function createIntlFormat(string $locale) : IntlFormat { $formatter = [MessageFormatter::createDateValueFormatter($locale), MessageFormatter::createNumberValueFormatter($locale), new TimeZoneFormatter($locale), new LocaleFormatter($locale)]; return new IntlFormat($formatter); }