String Locale::formatDateTime(const DateComponents& date, FormatType formatType) { if (date.getType() == DateComponents::Invalid) return String(); DateTimeStringBuilder builder(*this, date); switch (date.getType()) { case DateComponents::Time: builder.build(formatType == FormatTypeShort ? shortTimeFormat() : timeFormat()); break; case DateComponents::Date: builder.build(dateFormat()); break; case DateComponents::Month: builder.build(formatType == FormatTypeShort ? shortMonthFormat() : monthFormat()); break; case DateComponents::Week: builder.build(weekFormatInLDML()); break; case DateComponents::DateTime: case DateComponents::DateTimeLocal: builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSeconds() : dateTimeFormatWithSeconds()); break; case DateComponents::Invalid: ASSERT_NOT_REACHED(); break; } return builder.toString(); }
String LocaleWin::dateTimeFormatWithoutSeconds() { if (!m_dateTimeFormatWithoutSeconds.isNull()) return m_dateTimeFormatWithoutSeconds; StringBuilder builder; builder.append(dateFormat()); builder.append(' '); builder.append(shortTimeFormat()); m_dateTimeFormatWithoutSeconds = builder.toString(); return m_dateTimeFormatWithoutSeconds; }
TEST_F(LocaleWinTest, shortTimeFormat) { EXPECT_STREQ("h:mm a", shortTimeFormat(EnglishUS).utf8().data()); EXPECT_STREQ("HH:mm", shortTimeFormat(FrenchFR).utf8().data()); EXPECT_STREQ("H:mm", shortTimeFormat(JapaneseJP).utf8().data()); }