This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
#include "base/i18n/time_formatting.h"
#include "base/i18n/rtl.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/icu/source/common/unicode/uversion.h"
namespace base {
namespace {
const Time::Exploded kTestDateTimeExploded = {
2011, 4, 6, 30,
15, 42, 7, 0
};
TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) {
i18n::SetICUDefaultLocale("en_US");
Time time(Time::FromLocalExploded(kTestDateTimeExploded));
string16 clock24h(ASCIIToUTF16("15:42"));
string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
string16 clock12h(ASCIIToUTF16("3:42"));
EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time));
EXPECT_EQ(k12HourClock, GetHourClockType());
EXPECT_EQ(clock24h,
TimeFormatTimeOfDayWithHourClockType(time,
k24HourClock,
kKeepAmPm));
EXPECT_EQ(clock24h,
TimeFormatTimeOfDayWithHourClockType(time,
k24HourClock,
kDropAmPm));
EXPECT_EQ(clock12h_pm,
TimeFormatTimeOfDayWithHourClockType(time,
k12HourClock,
kKeepAmPm));
EXPECT_EQ(clock12h,
TimeFormatTimeOfDayWithHourClockType(time,
k12HourClock,
kDropAmPm));
}
TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) {
i18n::SetICUDefaultLocale("en_GB");
Time time(Time::FromLocalExploded(kTestDateTimeExploded));
string16 clock24h(ASCIIToUTF16("15:42"));
#if U_ICU_VERSION_MAJOR_NUM >= 50
string16 clock12h_pm(ASCIIToUTF16("3:42 pm"));
#else
string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
#endif
string16 clock12h(ASCIIToUTF16("3:42"));
EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
EXPECT_EQ(k24HourClock, GetHourClockType());
EXPECT_EQ(clock24h,
TimeFormatTimeOfDayWithHourClockType(time,
k24HourClock,
kKeepAmPm));
EXPECT_EQ(clock24h,
TimeFormatTimeOfDayWithHourClockType(time,
k24HourClock,
kDropAmPm));
EXPECT_EQ(clock12h_pm,
TimeFormatTimeOfDayWithHourClockType(time,
k12HourClock,
kKeepAmPm));
EXPECT_EQ(clock12h,
TimeFormatTimeOfDayWithHourClockType(time,
k12HourClock,
kDropAmPm));
}
TEST(TimeFormattingTest, TimeFormatTimeOfDayJP) {
i18n::SetICUDefaultLocale("ja_JP");
Time time(Time::FromLocalExploded(kTestDateTimeExploded));
string16 clock24h(ASCIIToUTF16("15:42"));
string16 clock12h_pm(WideToUTF16(L"\x5348\x5f8c" L"3:42"));
string16 clock12h(ASCIIToUTF16("3:42"));
EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
EXPECT_EQ(k24HourClock, GetHourClockType());
EXPECT_EQ(clock24h,
TimeFormatTimeOfDayWithHourClockType(time,
k24HourClock,
kKeepAmPm));
EXPECT_EQ(clock24h,
TimeFormatTimeOfDayWithHourClockType(time,
k24HourClock,
kDropAmPm));
EXPECT_EQ(clock12h_pm,
TimeFormatTimeOfDayWithHourClockType(time,
k12HourClock,
kKeepAmPm));
EXPECT_EQ(clock12h,
TimeFormatTimeOfDayWithHourClockType(time,
k12HourClock,
kDropAmPm));
}
TEST(TimeFormattingTest, TimeFormatDateUS) {
i18n::SetICUDefaultLocale("en_US");
Time time(Time::FromLocalExploded(kTestDateTimeExploded));
EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time));
EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time));
#if U_ICU_VERSION_MAJOR_NUM >= 50
EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"),
TimeFormatShortDateAndTime(time));
#else
EXPECT_EQ(ASCIIToUTF16("4/30/11 3:42:07 PM"),
TimeFormatShortDateAndTime(time));
#endif
#if U_ICU_VERSION_MAJOR_NUM >= 50
EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"),
TimeFormatFriendlyDateAndTime(time));
#else
EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 3:42:07 PM"),
TimeFormatFriendlyDateAndTime(time));
#endif
EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"),
TimeFormatFriendlyDate(time));
}
TEST(TimeFormattingTest, TimeFormatDateGB) {
i18n::SetICUDefaultLocale("en_GB");
Time time(Time::FromLocalExploded(kTestDateTimeExploded));
EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time));
EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time));
EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"),
TimeFormatShortDateAndTime(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"),
TimeFormatFriendlyDateAndTime(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"),
TimeFormatFriendlyDate(time));
}
}
}