19 #include "gmock/gmock.h" 20 #include "gtest/gtest.h" 24 using testing::HasSubstr;
31 const std::string& fmt,
const std::string& ans) {
35 EXPECT_EQ(
"xxx " + ans +
" yyy",
52 std::string big(128,
'x');
55 std::string bigger(100000,
'x');
71 TestFormatSpecifier(t, tz,
"%a",
"Thu");
72 TestFormatSpecifier(t, tz,
"%A",
"Thursday");
73 TestFormatSpecifier(t, tz,
"%b",
"Jan");
74 TestFormatSpecifier(t, tz,
"%B",
"January");
79 EXPECT_THAT(s, HasSubstr(
"1970"));
80 EXPECT_THAT(s, HasSubstr(
"00:00:00"));
82 TestFormatSpecifier(t, tz,
"%p",
"AM");
83 TestFormatSpecifier(t, tz,
"%x",
"01/01/70");
84 TestFormatSpecifier(t, tz,
"%X",
"00:00:00");
103 EXPECT_EQ(
"1969-12-31 23:59:59.999999",
110 EXPECT_EQ(
"2014-03-17 02:47:07.333304",
113 EXPECT_EQ(
"2014-03-17 02:47:07.333305",
122 EXPECT_EQ(
"Mon, 28 Jun 0077 09:08:07 +0000",
124 EXPECT_EQ(
"28 Jun 0077 09:08:07 +0000",
132 EXPECT_EQ(
"infinite-future",
134 EXPECT_EQ(
"infinite-past",
155 "2013-06-28 19:08:09 -0800", &t, &err))
178 absl::ParseTime(
"%Y-%m-%d %H:%M:%S",
"2013-06-28 19:08:09", tz, &t, &e))
186 "2013-06-28 19:08:09 +0800", tz, &t, &e))
198 EXPECT_THAT(err, HasSubstr(
"Illegal trailing data"));
205 EXPECT_FALSE(err.empty());
209 EXPECT_THAT(err, HasSubstr(
"Illegal trailing data"));
213 EXPECT_THAT(err, HasSubstr(
"Out-of-range"));
218 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
221 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
225 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
227 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
231 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
233 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
235 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
237 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
239 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
241 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
243 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
245 EXPECT_THAT(err, HasSubstr(
"Illegal trailing data"));
247 EXPECT_THAT(err, HasSubstr(
"Illegal trailing data"));
272 "%E*S",
"0.214748364801234567890123456789012345678901234567890123456789",
286 EXPECT_THAT(err, HasSubstr(
"Illegal trailing data"));
290 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
294 EXPECT_THAT(err, HasSubstr(
"Illegal trailing data"));
298 EXPECT_THAT(err, HasSubstr(
"Illegal trailing data"));
302 EXPECT_THAT(err, HasSubstr(
"Failed to parse"));
308 EXPECT_TRUE(
absl::ParseTime(
"%H:%M blah",
"infinite-future", &t, &err));
312 EXPECT_TRUE(
absl::ParseTime(
"%H:%M blah",
" infinite-future", &t, &err));
314 EXPECT_TRUE(
absl::ParseTime(
"%H:%M blah",
"infinite-future ", &t, &err));
316 EXPECT_TRUE(
absl::ParseTime(
"%H:%M blah",
" infinite-future ", &t, &err));
323 EXPECT_TRUE(
absl::ParseTime(
"%H:%M blah",
" infinite-past", &t, &err));
325 EXPECT_TRUE(
absl::ParseTime(
"%H:%M blah",
"infinite-past ", &t, &err));
327 EXPECT_TRUE(
absl::ParseTime(
"%H:%M blah",
" infinite-past ", &t, &err));
332 EXPECT_TRUE(
absl::ParseTime(
"infinite-future %H:%M",
"infinite-future 03:04",
340 absl::ParseTime(
"infinite-past %H:%M",
"infinite-past 03:04", &t, &err));
346 EXPECT_FALSE(
absl::ParseTime(
"infinite-future %H:%M",
"03:04", &t, &err));
347 EXPECT_FALSE(
absl::ParseTime(
"infinite-past %H:%M",
"03:04", &t, &err));
367 TEST(FormatParse, RoundTrip) {
378 const std::string s =
382 EXPECT_EQ(in + subseconds, out);
403 #if !defined(_MSC_VER) && !defined(__EMSCRIPTEN__) 412 #endif // !_MSC_VER && !__EMSCRIPTEN__ 415 TEST(FormatParse, RoundTripDistantFuture) {
428 TEST(FormatParse, RoundTripDistantPast) {
CivilInfo At(Time t) const
const char RFC1123_no_wday[]
CONSTEXPR_M int minute() const noexcept
constexpr Time InfiniteFuture()
constexpr Duration Hours(int64_t n)
std::string FormatTime(const std::string &format, absl::Time t, absl::TimeZone tz)
TimeZone FixedTimeZone(int seconds)
const char RFC3339_full[]
bool ParseTime(const std::string &format, const std::string &input, absl::Time *time, std::string *err)
constexpr Duration Microseconds(int64_t n)
constexpr Duration Milliseconds(int64_t n)
constexpr Time FromUnixSeconds(int64_t s)
constexpr Time UnixEpoch()
constexpr Time FromUnixMicros(int64_t us)
constexpr Duration Minutes(int64_t n)
constexpr Duration Seconds(int64_t n)
Time FromCivil(CivilSecond ct, TimeZone tz)
const char RFC1123_full[]
TEST(Symbolize, Unimplemented)
TimeZone LoadTimeZone(const std::string &name)
constexpr Duration Nanoseconds(int64_t n)
CONSTEXPR_M int hour() const noexcept
constexpr Duration ZeroDuration()
constexpr Time FromTimeT(time_t t)
constexpr Time InfinitePast()