Abseil Common Libraries (C++) (grcp 依赖) https://abseil.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

441 lines
16 KiB

7 years ago
// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstdint>
#include <limits>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/internal/test_util.h"
#include "absl/time/time.h"
using testing::HasSubstr;
namespace {
// A helper that tests the given format specifier by itself, and with leading
// and trailing characters. For example: TestFormatSpecifier(t, "%a", "Thu").
void TestFormatSpecifier(absl::Time t, absl::TimeZone tz, const std::string& fmt,
const std::string& ans) {
EXPECT_EQ(ans, absl::FormatTime(fmt, t, tz));
EXPECT_EQ("xxx " + ans, absl::FormatTime("xxx " + fmt, t, tz));
EXPECT_EQ(ans + " yyy", absl::FormatTime(fmt + " yyy", t, tz));
EXPECT_EQ("xxx " + ans + " yyy",
absl::FormatTime("xxx " + fmt + " yyy", t, tz));
}
//
// Testing FormatTime()
//
TEST(FormatTime, Basics) {
absl::TimeZone tz = absl::UTCTimeZone();
absl::Time t = absl::FromTimeT(0);
// Starts with a couple basic edge cases.
EXPECT_EQ("", absl::FormatTime("", t, tz));
EXPECT_EQ(" ", absl::FormatTime(" ", t, tz));
EXPECT_EQ(" ", absl::FormatTime(" ", t, tz));
EXPECT_EQ("xxx", absl::FormatTime("xxx", t, tz));
std::string big(128, 'x');
EXPECT_EQ(big, absl::FormatTime(big, t, tz));
// Cause the 1024-byte buffer to grow.
std::string bigger(100000, 'x');
EXPECT_EQ(bigger, absl::FormatTime(bigger, t, tz));
t += absl::Hours(13) + absl::Minutes(4) + absl::Seconds(5);
t += absl::Milliseconds(6) + absl::Microseconds(7) + absl::Nanoseconds(8);
EXPECT_EQ("1970-01-01", absl::FormatTime("%Y-%m-%d", t, tz));
EXPECT_EQ("13:04:05", absl::FormatTime("%H:%M:%S", t, tz));
EXPECT_EQ("13:04:05.006", absl::FormatTime("%H:%M:%E3S", t, tz));
EXPECT_EQ("13:04:05.006007", absl::FormatTime("%H:%M:%E6S", t, tz));
EXPECT_EQ("13:04:05.006007008", absl::FormatTime("%H:%M:%E9S", t, tz));
}
TEST(FormatTime, LocaleSpecific) {
const absl::TimeZone tz = absl::UTCTimeZone();
absl::Time t = absl::FromTimeT(0);
TestFormatSpecifier(t, tz, "%a", "Thu");
TestFormatSpecifier(t, tz, "%A", "Thursday");
TestFormatSpecifier(t, tz, "%b", "Jan");
TestFormatSpecifier(t, tz, "%B", "January");
// %c should at least produce the numeric year and time-of-day.
const std::string s =
absl::FormatTime("%c", absl::FromTimeT(0), absl::UTCTimeZone());
EXPECT_THAT(s, HasSubstr("1970"));
EXPECT_THAT(s, HasSubstr("00:00:00"));
TestFormatSpecifier(t, tz, "%p", "AM");
TestFormatSpecifier(t, tz, "%x", "01/01/70");
TestFormatSpecifier(t, tz, "%X", "00:00:00");
}
TEST(FormatTime, ExtendedSeconds) {
const absl::TimeZone tz = absl::UTCTimeZone();
// No subseconds.
absl::Time t = absl::FromTimeT(0) + absl::Seconds(5);
EXPECT_EQ("05", absl::FormatTime("%E*S", t, tz));
EXPECT_EQ("05.000000000000000", absl::FormatTime("%E15S", t, tz));
// With subseconds.
t += absl::Milliseconds(6) + absl::Microseconds(7) + absl::Nanoseconds(8);
EXPECT_EQ("05.006007008", absl::FormatTime("%E*S", t, tz));
EXPECT_EQ("05", absl::FormatTime("%E0S", t, tz));
EXPECT_EQ("05.006007008000000", absl::FormatTime("%E15S", t, tz));
// Times before the Unix epoch.
t = absl::FromUnixMicros(-1);
EXPECT_EQ("1969-12-31 23:59:59.999999",
absl::FormatTime("%Y-%m-%d %H:%M:%E*S", t, tz));
// Here is a "%E*S" case we got wrong for a while. While the first
// instant below is correctly rendered as "...:07.333304", the second
// one used to appear as "...:07.33330499999999999".
t = absl::FromUnixMicros(1395024427333304);
EXPECT_EQ("2014-03-17 02:47:07.333304",
absl::FormatTime("%Y-%m-%d %H:%M:%E*S", t, tz));
t += absl::Microseconds(1);
EXPECT_EQ("2014-03-17 02:47:07.333305",
absl::FormatTime("%Y-%m-%d %H:%M:%E*S", t, tz));
}
TEST(FormatTime, RFC1123FormatPadsYear) { // locale specific
absl::TimeZone tz = absl::UTCTimeZone();
// A year of 77 should be padded to 0077.
absl::Time t = absl::FromCivil(absl::CivilSecond(77, 6, 28, 9, 8, 7), tz);
7 years ago
EXPECT_EQ("Mon, 28 Jun 0077 09:08:07 +0000",
absl::FormatTime(absl::RFC1123_full, t, tz));
EXPECT_EQ("28 Jun 0077 09:08:07 +0000",
absl::FormatTime(absl::RFC1123_no_wday, t, tz));
}
TEST(FormatTime, InfiniteTime) {
absl::TimeZone tz = absl::time_internal::LoadTimeZone("America/Los_Angeles");
// The format and timezone are ignored.
EXPECT_EQ("infinite-future",
absl::FormatTime("%H:%M blah", absl::InfiniteFuture(), tz));
EXPECT_EQ("infinite-past",
absl::FormatTime("%H:%M blah", absl::InfinitePast(), tz));
}
//
// Testing ParseTime()
//
TEST(ParseTime, Basics) {
absl::Time t = absl::FromTimeT(1234567890);
std::string err;
// Simple edge cases.
EXPECT_TRUE(absl::ParseTime("", "", &t, &err)) << err;
EXPECT_EQ(absl::UnixEpoch(), t); // everything defaulted
EXPECT_TRUE(absl::ParseTime(" ", " ", &t, &err)) << err;
EXPECT_TRUE(absl::ParseTime(" ", " ", &t, &err)) << err;
EXPECT_TRUE(absl::ParseTime("x", "x", &t, &err)) << err;
EXPECT_TRUE(absl::ParseTime("xxx", "xxx", &t, &err)) << err;
EXPECT_TRUE(absl::ParseTime("%Y-%m-%d %H:%M:%S %z",
"2013-06-28 19:08:09 -0800", &t, &err))
<< err;
const auto ci = absl::FixedTimeZone(-8 * 60 * 60).At(t);
EXPECT_EQ(absl::CivilSecond(2013, 6, 28, 19, 8, 9), ci.cs);
EXPECT_EQ(absl::ZeroDuration(), ci.subsecond);
7 years ago
}
TEST(ParseTime, NullErrorString) {
absl::Time t;
EXPECT_FALSE(absl::ParseTime("%Q", "invalid format", &t, nullptr));
EXPECT_FALSE(absl::ParseTime("%H", "12 trailing data", &t, nullptr));
EXPECT_FALSE(
absl::ParseTime("%H out of range", "42 out of range", &t, nullptr));
}
TEST(ParseTime, WithTimeZone) {
const absl::TimeZone tz =
absl::time_internal::LoadTimeZone("America/Los_Angeles");
absl::Time t;
std::string e;
// We can parse a std::string without a UTC offset if we supply a timezone.
EXPECT_TRUE(
absl::ParseTime("%Y-%m-%d %H:%M:%S", "2013-06-28 19:08:09", tz, &t, &e))
<< e;
auto ci = tz.At(t);
EXPECT_EQ(absl::CivilSecond(2013, 6, 28, 19, 8, 9), ci.cs);
EXPECT_EQ(absl::ZeroDuration(), ci.subsecond);
7 years ago
// But the timezone is ignored when a UTC offset is present.
EXPECT_TRUE(absl::ParseTime("%Y-%m-%d %H:%M:%S %z",
"2013-06-28 19:08:09 +0800", tz, &t, &e))
<< e;
ci = absl::FixedTimeZone(8 * 60 * 60).At(t);
EXPECT_EQ(absl::CivilSecond(2013, 6, 28, 19, 8, 9), ci.cs);
EXPECT_EQ(absl::ZeroDuration(), ci.subsecond);
7 years ago
}
TEST(ParseTime, ErrorCases) {
absl::Time t = absl::FromTimeT(0);
std::string err;
EXPECT_FALSE(absl::ParseTime("%S", "123", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Illegal trailing data"));
// Can't parse an illegal format specifier.
err.clear();
EXPECT_FALSE(absl::ParseTime("%Q", "x", &t, &err)) << err;
// Exact contents of "err" are platform-dependent because of
// differences in the strptime implementation between OSX and Linux.
EXPECT_FALSE(err.empty());
// Fails because of trailing, unparsed data "blah".
EXPECT_FALSE(absl::ParseTime("%m-%d", "2-3 blah", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Illegal trailing data"));
// Feb 31 requires normalization.
EXPECT_FALSE(absl::ParseTime("%m-%d", "2-31", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Out-of-range"));
// Check that we cannot have spaces in UTC offsets.
EXPECT_TRUE(absl::ParseTime("%z", "-0203", &t, &err)) << err;
EXPECT_FALSE(absl::ParseTime("%z", "- 2 3", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_TRUE(absl::ParseTime("%Ez", "-02:03", &t, &err)) << err;
EXPECT_FALSE(absl::ParseTime("%Ez", "- 2: 3", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
// Check that we reject other malformed UTC offsets.
EXPECT_FALSE(absl::ParseTime("%Ez", "+-08:00", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%Ez", "-+08:00", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
// Check that we do not accept "-0" in fields that allow zero.
EXPECT_FALSE(absl::ParseTime("%Y", "-0", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%E4Y", "-0", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%H", "-0", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%M", "-0", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%S", "-0", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%z", "+-000", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%Ez", "+-0:00", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
EXPECT_FALSE(absl::ParseTime("%z", "-00-0", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Illegal trailing data"));
EXPECT_FALSE(absl::ParseTime("%Ez", "-00:-0", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Illegal trailing data"));
}
TEST(ParseTime, ExtendedSeconds) {
std::string err;
absl::Time t;
// Here is a "%E*S" case we got wrong for a while. The fractional
// part of the first instant is less than 2^31 and was correctly
// parsed, while the second (and any subsecond field >=2^31) failed.
t = absl::UnixEpoch();
EXPECT_TRUE(absl::ParseTime("%E*S", "0.2147483647", &t, &err)) << err;
EXPECT_EQ(absl::UnixEpoch() + absl::Nanoseconds(214748364) +
absl::Nanoseconds(1) / 2,
t);
t = absl::UnixEpoch();
EXPECT_TRUE(absl::ParseTime("%E*S", "0.2147483648", &t, &err)) << err;
EXPECT_EQ(absl::UnixEpoch() + absl::Nanoseconds(214748364) +
absl::Nanoseconds(3) / 4,
t);
// We should also be able to specify long strings of digits far
// beyond the current resolution and have them convert the same way.
t = absl::UnixEpoch();
EXPECT_TRUE(absl::ParseTime(
"%E*S", "0.214748364801234567890123456789012345678901234567890123456789",
&t, &err))
<< err;
EXPECT_EQ(absl::UnixEpoch() + absl::Nanoseconds(214748364) +
absl::Nanoseconds(3) / 4,
t);
}
TEST(ParseTime, ExtendedOffsetErrors) {
std::string err;
absl::Time t;
// %z against +-HHMM.
EXPECT_FALSE(absl::ParseTime("%z", "-123", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Illegal trailing data"));
// %z against +-HH.
EXPECT_FALSE(absl::ParseTime("%z", "-1", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
// %Ez against +-HH:MM.
EXPECT_FALSE(absl::ParseTime("%Ez", "-12:3", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Illegal trailing data"));
// %Ez against +-HHMM.
EXPECT_FALSE(absl::ParseTime("%Ez", "-123", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Illegal trailing data"));
// %Ez against +-HH.
EXPECT_FALSE(absl::ParseTime("%Ez", "-1", &t, &err)) << err;
EXPECT_THAT(err, HasSubstr("Failed to parse"));
}
TEST(ParseTime, InfiniteTime) {
absl::Time t;
std::string err;
EXPECT_TRUE(absl::ParseTime("%H:%M blah", "infinite-future", &t, &err));
EXPECT_EQ(absl::InfiniteFuture(), t);
// Surrounding whitespace.
EXPECT_TRUE(absl::ParseTime("%H:%M blah", " infinite-future", &t, &err));
EXPECT_EQ(absl::InfiniteFuture(), t);
EXPECT_TRUE(absl::ParseTime("%H:%M blah", "infinite-future ", &t, &err));
EXPECT_EQ(absl::InfiniteFuture(), t);
EXPECT_TRUE(absl::ParseTime("%H:%M blah", " infinite-future ", &t, &err));
EXPECT_EQ(absl::InfiniteFuture(), t);
EXPECT_TRUE(absl::ParseTime("%H:%M blah", "infinite-past", &t, &err));
EXPECT_EQ(absl::InfinitePast(), t);
// Surrounding whitespace.
EXPECT_TRUE(absl::ParseTime("%H:%M blah", " infinite-past", &t, &err));
EXPECT_EQ(absl::InfinitePast(), t);
EXPECT_TRUE(absl::ParseTime("%H:%M blah", "infinite-past ", &t, &err));
EXPECT_EQ(absl::InfinitePast(), t);
EXPECT_TRUE(absl::ParseTime("%H:%M blah", " infinite-past ", &t, &err));
EXPECT_EQ(absl::InfinitePast(), t);
// "infinite-future" as literal std::string
absl::TimeZone tz = absl::UTCTimeZone();
EXPECT_TRUE(absl::ParseTime("infinite-future %H:%M", "infinite-future 03:04",
&t, &err));
EXPECT_NE(absl::InfiniteFuture(), t);
EXPECT_EQ(3, tz.At(t).cs.hour());
EXPECT_EQ(4, tz.At(t).cs.minute());
7 years ago
// "infinite-past" as literal std::string
EXPECT_TRUE(
absl::ParseTime("infinite-past %H:%M", "infinite-past 03:04", &t, &err));
EXPECT_NE(absl::InfinitePast(), t);
EXPECT_EQ(3, tz.At(t).cs.hour());
EXPECT_EQ(4, tz.At(t).cs.minute());
7 years ago
// The input doesn't match the format.
EXPECT_FALSE(absl::ParseTime("infinite-future %H:%M", "03:04", &t, &err));
EXPECT_FALSE(absl::ParseTime("infinite-past %H:%M", "03:04", &t, &err));
}
TEST(ParseTime, FailsOnUnrepresentableTime) {
const absl::TimeZone utc = absl::UTCTimeZone();
absl::Time t;
EXPECT_FALSE(
absl::ParseTime("%Y-%m-%d", "-292277022657-01-27", utc, &t, nullptr));
EXPECT_TRUE(
absl::ParseTime("%Y-%m-%d", "-292277022657-01-28", utc, &t, nullptr));
EXPECT_TRUE(
absl::ParseTime("%Y-%m-%d", "292277026596-12-04", utc, &t, nullptr));
EXPECT_FALSE(
absl::ParseTime("%Y-%m-%d", "292277026596-12-05", utc, &t, nullptr));
}
//
// Roundtrip test for FormatTime()/ParseTime().
//
TEST(FormatParse, RoundTrip) {
const absl::TimeZone lax =
7 years ago
absl::time_internal::LoadTimeZone("America/Los_Angeles");
const absl::Time in =
absl::FromCivil(absl::CivilSecond(1977, 6, 28, 9, 8, 7), lax);
7 years ago
const absl::Duration subseconds = absl::Nanoseconds(654321);
std::string err;
// RFC3339, which renders subseconds.
{
absl::Time out;
const std::string s = absl::FormatTime(absl::RFC3339_full, in + subseconds, lax);
7 years ago
EXPECT_TRUE(absl::ParseTime(absl::RFC3339_full, s, &out, &err))
<< s << ": " << err;
EXPECT_EQ(in + subseconds, out); // RFC3339_full includes %Ez
}
// RFC1123, which only does whole seconds.
{
absl::Time out;
const std::string s = absl::FormatTime(absl::RFC1123_full, in, lax);
7 years ago
EXPECT_TRUE(absl::ParseTime(absl::RFC1123_full, s, &out, &err))
<< s << ": " << err;
EXPECT_EQ(in, out); // RFC1123_full includes %z
}
// `absl::FormatTime()` falls back to strftime() for "%c", which appears to
// work. On Windows, `absl::ParseTime()` falls back to std::get_time() which
// appears to fail on "%c" (or at least on the "%c" text produced by
// `strftime()`). This makes it fail the round-trip test.
Export of internal Abseil changes. -- 5f1ab09522226336830d9ea6ef7276d37f536ac5 by Abseil Team <absl-team@google.com>: Clarify the documentation of ABSL_MUST_USE_RESULT. PiperOrigin-RevId: 221663609 -- af4c8359a20d56369fd1dce318220cf3be03ca66 by Greg Falcon <gfalcon@google.com>: Internal change PiperOrigin-RevId: 221538448 -- 487cd09bd1942bf607080deeae38fee6ce66f294 by Eric Fiselier <ericwf@google.com>: Work around emscripten bugs and missing features in absl/time:time_test. The emscripten toolchain has a couple of issues that cause time_test to fail. Specifically: 1) emscripten doesn't support signals. 2) The javascript implementation of strftime/strptime use different expansions of '%c' that mean it doesn't round-trip. PiperOrigin-RevId: 221523701 -- 5823652e6a200b97b07334bc47128dfac40e20fc by Xiaoyi Zhang <zhangxy@google.com>: Fix MSVC compiler warning by explicitly casting to char. Currently our MSVC build breaks with the following error: raw_hash_set.h(406): warning C4309: 'argument': truncation of constant value PiperOrigin-RevId: 221492585 -- c5806358320711a5efbe5c523df13e14ab53a17d by Greg Falcon <gfalcon@google.com>: Replace calls to getpagesize() with the more portable sysconf(_SC_PAGESIZE); the latter is in POSIX 1.0 and is called out in the Linux `getpagesize` man page as a more portable spelling. PiperOrigin-RevId: 221492471 -- 19ffe82851072229bb7ce73f754ffe4c18e8c575 by Abseil Team <absl-team@google.com>: Fix -Wundef error in absl/hash/internal/hash.h. PiperOrigin-RevId: 221444120 -- b30f3d0a848563b6e4ec33f3dc085831dfabb748 by Jon Cohen <cohenjon@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 221339736 GitOrigin-RevId: 5f1ab09522226336830d9ea6ef7276d37f536ac5 Change-Id: I96223d522d98bf6616dea88eb047c2d536eeddd0
6 years ago
//
// Under the emscripten compiler `absl::ParseTime() falls back to
// `strptime()`, but that ends up using a different definition for "%c"
// compared to `strftime()`, also causing the round-trip test to fail
// (see https://github.com/kripken/emscripten/pull/7491).
#if !defined(_MSC_VER) && !defined(__EMSCRIPTEN__)
7 years ago
// Even though we don't know what %c will produce, it should roundtrip,
// but only in the 0-offset timezone.
{
absl::Time out;
const std::string s = absl::FormatTime("%c", in, absl::UTCTimeZone());
EXPECT_TRUE(absl::ParseTime("%c", s, &out, &err)) << s << ": " << err;
EXPECT_EQ(in, out);
}
Export of internal Abseil changes. -- 5f1ab09522226336830d9ea6ef7276d37f536ac5 by Abseil Team <absl-team@google.com>: Clarify the documentation of ABSL_MUST_USE_RESULT. PiperOrigin-RevId: 221663609 -- af4c8359a20d56369fd1dce318220cf3be03ca66 by Greg Falcon <gfalcon@google.com>: Internal change PiperOrigin-RevId: 221538448 -- 487cd09bd1942bf607080deeae38fee6ce66f294 by Eric Fiselier <ericwf@google.com>: Work around emscripten bugs and missing features in absl/time:time_test. The emscripten toolchain has a couple of issues that cause time_test to fail. Specifically: 1) emscripten doesn't support signals. 2) The javascript implementation of strftime/strptime use different expansions of '%c' that mean it doesn't round-trip. PiperOrigin-RevId: 221523701 -- 5823652e6a200b97b07334bc47128dfac40e20fc by Xiaoyi Zhang <zhangxy@google.com>: Fix MSVC compiler warning by explicitly casting to char. Currently our MSVC build breaks with the following error: raw_hash_set.h(406): warning C4309: 'argument': truncation of constant value PiperOrigin-RevId: 221492585 -- c5806358320711a5efbe5c523df13e14ab53a17d by Greg Falcon <gfalcon@google.com>: Replace calls to getpagesize() with the more portable sysconf(_SC_PAGESIZE); the latter is in POSIX 1.0 and is called out in the Linux `getpagesize` man page as a more portable spelling. PiperOrigin-RevId: 221492471 -- 19ffe82851072229bb7ce73f754ffe4c18e8c575 by Abseil Team <absl-team@google.com>: Fix -Wundef error in absl/hash/internal/hash.h. PiperOrigin-RevId: 221444120 -- b30f3d0a848563b6e4ec33f3dc085831dfabb748 by Jon Cohen <cohenjon@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 221339736 GitOrigin-RevId: 5f1ab09522226336830d9ea6ef7276d37f536ac5 Change-Id: I96223d522d98bf6616dea88eb047c2d536eeddd0
6 years ago
#endif // !_MSC_VER && !__EMSCRIPTEN__
7 years ago
}
TEST(FormatParse, RoundTripDistantFuture) {
const absl::TimeZone tz = absl::UTCTimeZone();
const absl::Time in =
absl::FromUnixSeconds(std::numeric_limits<int64_t>::max());
std::string err;
absl::Time out;
const std::string s = absl::FormatTime(absl::RFC3339_full, in, tz);
EXPECT_TRUE(absl::ParseTime(absl::RFC3339_full, s, &out, &err))
<< s << ": " << err;
EXPECT_EQ(in, out);
}
TEST(FormatParse, RoundTripDistantPast) {
const absl::TimeZone tz = absl::UTCTimeZone();
const absl::Time in =
absl::FromUnixSeconds(std::numeric_limits<int64_t>::min());
std::string err;
absl::Time out;
const std::string s = absl::FormatTime(absl::RFC3339_full, in, tz);
EXPECT_TRUE(absl::ParseTime(absl::RFC3339_full, s, &out, &err))
<< s << ": " << err;
EXPECT_EQ(in, out);
}
Changes imported from Abseil "staging" branch: - 06c8c67f5a564d00696e023060f05a5c34e7e164 IWYU | absl/base by Juemin Yang <jueminyang@google.com> - 2b1a054a09bda55843b449843b2a125741e936e7 Internal refactoring by Greg Miller <jgm@google.com> - f43f7f1f91bee26b5ddcd0c5bbbc47cb977aef77 Make std::hash<absl::optional<T>> to be standard compliant: by Xiaoyi Zhang <zhangxy@google.com> - 539bad2ebc22e610e1f292285a30a87945bc663e Update utility.h to Abseil standards by Tom Manshreck <shreck@google.com> - d05ec10a5f16a5d6640e0db91ecc7ab3ea971fd4 Add a test for absl::Barrier. by Derek Mauro <dmauro@google.com> - d707e27acb3c06f0d74c5f7ad7861e3841a5471f Run leak-checking tool over all outbound code. by Daniel Katz <katzdm@google.com> - 55f07f482a50422b8f99f7176374a19d0d473c5f Add alignas(16) to uint128. by Alex Strelnikov <strel@google.com> - 94999b7edde82308f736fb939501537ee9edbca6 Update attributes.h to Abseil standards by Tom Manshreck <shreck@google.com> - 321bed0061c41b53d0206ad4865528c00dd6d825 Test git merge + piper cl process by Juemin Yang <jueminyang@google.com> - 69920e7351a1053a7f4940bbde1768e839ce84bc Adds support for "/etc/localtime" as an embedded time zon... by Greg Miller <jgm@google.com> - 6839c06bf232903d3a9cbffa6eb2c960db78e67b Add copyright notices to inlined_vector code. by Greg Falcon <gfalcon@google.com> - 4e2714f6266263515cdfd31675c30c6ed6f98e1a Adding Apache 2.0 License by Gennadiy Civil <misterg@google.com> - 7402e7594016a4cd0a8b823fe6bc1bad1874bb85 IWYU | absl/utility by Juemin Yang <jueminyang@google.com> - 271a3812337eed97c412042738482688a80e19bd IWYU | absl/memory by Juemin Yang <jueminyang@google.com> - 32bda13a8098c2b06e25a5cf7bb782d6b79eb006 IWYU | absl/numeric by Juemin Yang <jueminyang@google.com> - 62d375cedc133108904bc06e340e303091a565df Remove "no_test"-annotations on span_test_noexceptions. by Daniel Katz <katzdm@google.com> - ebcbae9a55a93a7f1bb6862edc2715a6d9877206 Move CI-testing support files out of public-facing reposi... by Daniel Katz <katzdm@google.com> - d3f05eff4daa6030bfacb31cca0f9213fb702247 Fixes ToInt64Minutes() and ToInt64Hours() to properly sat... by Greg Miller <jgm@google.com> - b8dfae3facb6bb002622f083a10d14448f19e6e0 Fix typo. by Abseil Team <absl-team@google.com> - 150f03baa0afa231c2fc01597ea2321da586caba Update README.md by Yilei Yang <yileiyang@google.com> - 05276aa837dd081686518fd27bda4bd206ac4443 Adding Apache 2.0 License by Gennadiy Civil <misterg@google.com> - 37bf8e223e79ad06a195e28db9499e0c3d140f73 IWYU | absl/container by Juemin Yang <jueminyang@google.com> - 49164928f220978a32f88d16a55549bdf871daef IWYU | absl/algorithm by Juemin Yang <jueminyang@google.com> - a6804734e129039f9580a4fcd0f66425d0d0ac30 Move throw delegate wrappers to an internal namespace. by Greg Falcon <gfalcon@google.com> - ac83e73f67f593e2aff957b2be0b28e59c552a71 Fix error in comment stripping directives. by Greg Falcon <gfalcon@google.com> - e018a24185a984e787fb81a75fc35b74ad3a4d3d Update copyright headers all BUILD files by Gennadiy Civil <misterg@google.com> - a3be0990bfd76b0dec76bd85cecfa4dcec68b3ea Fix closing namespace comment typo. by Abseil Team <absl-team@google.com> - be3e3c4327e4f83949e0f29fd7a190d7eaa8b50b Update TODO by Abseil Team <absl-team@google.com> - f56a5d6f72685d92bb9c2905841b950d8177210c Add test-coverage for leak-sanitizer. by Daniel Katz <katzdm@google.com> - 7694bf161c7e00fdd08bfadc2aaf8e0fb09335f8 span.h: further touch up wording around the std::initiali... by Abseil Team <absl-team@google.com> - 3a12e081c0f8b359973e020d1e91f65356548ebc Update time.h to Abseil standards by Tom Manshreck <shreck@google.com> - 48d28f6468129420f4b20d451dca8e08012a7a77 Remove references to google from comments in Abseil. by Greg Falcon <gfalcon@google.com> - 773e34402d15fcad6370d5ed2430482d17db910d Rename the ExpectTime macro to match Abseil naming conven... by Greg Falcon <gfalcon@google.com> - 774d2ff1fe26c7313b301ff203e83e1aaac86627 Internal change. by Daniel Katz <katzdm@google.com> - 2e8a5830e95c8a1b839721bb2f1d4f5c85b9fb60 Fix typo in comment (missing '*' on a pointer). by Abseil Team <absl-team@google.com> - 458106feb707cf9609dd243713bde44aa9679e2a Correct capitalization: github -> GitHub by Yilei Yang <yileiyang@google.com> - af440725f02c2a83ca5cbaf176e1142f9e9d9b2f Update copyright headers by Gennadiy Civil <misterg@google.com> - 05b1118cce4ab87d23c33d48e64a96bcfec08761 Update copyright headers by Gennadiy Civil <misterg@google.com> - d5c6669a62d047156bb77055c5da03ee1b3c61b9 Update Abseil README to include descriptions of the inclu... by Tom Manshreck <shreck@google.com> - 3cd7e4663dddc840087469a6495f6cf433bfad8d Update copyright headers in //base by Tom Manshreck <shreck@google.com> - 7a876da657cd6698c5da2008a582d52eedc85dd1 Update strings overview with robust string library docume... by Tom Manshreck <shreck@google.com> - d9e3d0768d6f1c77d30992bdbef7b47ec92994bb Update copyright headers all BUILD files by Abseil Team <absl-team@google.com> - 6fe942728bceb0625f7c79b2840c4a6154d076b3 Make InlinedVector, FixedArray, and Span's at() throw on ... by Jon Cohen <cohenjon@google.com> - 5b52d5ec6cb9fbb07fc2e2fa020bd3eeb48c4953 Update clock.h to Abseil standards by Tom Manshreck <shreck@google.com> - c03c1ca3aee8bb7e40aa0315f6c432d31a72c30c Update //algorithm copyright headers by Tom Manshreck <shreck@google.com> - d46f40ddc596aaacb0459351d0e4aa6871289fa2 Temporarily prevent running mutex_test on crosstool17, wh... by Jon Cohen <cohenjon@google.com> - 61f11476189df68edfb9908308d677a91f03ff67 Update copyright headers in //container by Tom Manshreck <shreck@google.com> - 91832c00948954edf0b3dda12219c9a0202421ac Update copyright headers for //synchronization by Tom Manshreck <shreck@google.com> - 4e09100264b4585af6b4508ff35b9c627ac1f1ce Update copyright headers all BUILD files by Gennadiy Civil <misterg@google.com> - 13a0e8aebedec0f95b33750cbcd6b5548619b2a5 Update copyright headers in //memory by Tom Manshreck <shreck@google.com> - 63e1b9d4fdbcdf097e5276050ad1f76f0053e553 Update copyright headers for //strings (+ one from //nume... by Tom Manshreck <shreck@google.com> - 0108e7cfc50777a94c56d00e9c305161364df341 Convert ASSERT and EXPECT to ABSL_RAW_CHECK in helper fun... by Derek Mauro <dmauro@google.com> - 0122306fe47a3093248254a1b475c3a1d82abec5 Internal change by Abseil Team <absl-team@google.com> - 89c0c2698c98a12cd63172eeb02063b2f67e7c81 #absl Fix comment. by Abseil Team <absl-team@google.com> - 6621cc1ff54800e0aadb5e3071dbaa84b2077ceb Publishing contributing guidelines. by Gennadiy Civil <misterg@google.com> - e48c5be3c75e794b3e3827d40915b01fe1a1afc5 Avoid PRIdPTR. Cast to long long and use %lld insted. by Abseil Team <absl-team@google.com> - 2640ea4a260d89b94b07a3142660327e47db33fd No algorithmic changes. by Abseil Team <absl-team@google.com> - 1bc6c1bad17754f5d84963bf1d0db279402a0a1d Internal change. by Derek Mauro <dmauro@google.com> - 6845d24733e8c95bebde825ba78a2abfd9e35bdb span.h: fix up incorrect wording around lvalues. by Abseil Team <absl-team@google.com> - d8f5caee721e252e5f9b1080fb996363f498ac28 Add more exaustive Mutex testing. by Derek Mauro <dmauro@google.com> - e8b4cb053eb98858eef10cc53280b6ed5d6815a7 Change Span::subspan to not call into a deprecated constr... by Jon Cohen <cohenjon@google.com> - 49c36a82b3114926390557670aaaf0ea25b5760c s/std::size_t/size_t/g by Jon Cohen <cohenjon@google.com> - e17487c3c4d4a99f2fd8bc3e42176fc3171614d1 Account for the case of timeval::tv_sec being smaller than by Abseil Team <absl-team@google.com> - ecbb89d5fb98483e777c03d97ac02d7b7b54985e Alias absl::string_view to std::string_view when C++17 st... by Xiaoyi Zhang <zhangxy@google.com> - 6820e5a51459cdbb6a423cbae25a0cc839c85d44 Internal cleanup. by Xiaoyi Zhang <zhangxy@google.com> - 6976469b76a6faaf4111a24ddb37f40211ffadae More Span constexpr by Jon Cohen <cohenjon@google.com> - 8521c8956eee1125b7759eb272ec4a5a86fcefc5 #absl Fix comment. by Abseil Team <absl-team@google.com> - 20eae7a67fde5dd809aa47e5f7de8a493701645e Embed enough zoneinfo data to make time:time_test (under ... by Abseil Team <absl-team@google.com> - 841f5d98ceef4a423839ea73ee06c2f47a9b9680 Clean up macros in attributes.h | ATTRIBUTE_INITIAL_EXEC by Juemin Yang <jueminyang@google.com> - 83d8b36656e47919b5d0bac82eece897e195697e Update any.h comments to Abseil standards by Tom Manshreck <shreck@google.com> - bb3fae11d3459eeae2f63bfd22e65d3193187cc8 Update type_traits.h comments to Abseil standards by Tom Manshreck <shreck@google.com> - 992e1b07c0dec64271f8c44f22fd8df3734d0c47 Renamespace CycleClock code. by Greg Falcon <gfalcon@google.com> - 08d6fb0594098493ffbc0e737405182638122e7e Eliminate more existing lint warnings by Gennadiy Rozental <rogeeff@google.com> - 1cc6fdc71eb777497239f8c3e9168e6c9d40ea53 Update optional.h to Abseil standards by Tom Manshreck <shreck@google.com> - baa91747aa55009a9eb31b6072e33db06cfce2d2 Enforce internal namespace symbol reference policy by Gennadiy Rozental <rogeeff@google.com> - 939251e39342ce559e5d23fe43799671581f7cf5 Add CycleClock scaling shift to mitigate a possible overf... by Derek Mauro <dmauro@google.com> - c6dfdeecea0c7470938bed47c99ea2b2a95889d8 Add constexpr tests for absl::make_optional(). by Xiaoyi Zhang <zhangxy@google.com> - 509e949b992db33041d840746fbd05cc01cb206e Alias absl::optional to std::optional when C++17 std::opt... by Xiaoyi Zhang <zhangxy@google.com> - a1ae6d96a8826ba75281cac8632a766b5856acaf Remove no_test_* tags from span_test to increase test cov... by Xiaoyi Zhang <zhangxy@google.com> - 3c2a43cc09791723c8a324836629644ac44cb9c8 Remove accidental bits of Google-internal code and short ... by Greg Falcon <gfalcon@google.com> - 4874d49d496ac0b6ec36f4280a14b2159e7af930 Replaces the macro-generated Duration factory functions e... by Greg Miller <jgm@google.com> - 90e62695e03cb4a57e137ca0c3e116b1d802db57 Fix namespacing for a couple files in base/internal, and ... by Greg Falcon <gfalcon@google.com> - b0e6e00e34f967924849aaf8c123bba068f093e3 Publishing contributing guidelines. by Gennadiy Civil <misterg@google.com> - d74eafbccc3dffa6c25f9b6a2219425a24b5a959 Internal change by Abseil Team <absl-team@google.com> - 27477badbbf720265f5b9509b6c0e01913dc0a9f Update escaping.h comments to Abseil standards by Tom Manshreck <shreck@google.com> - 67002f55738319c2875197c3b6282de215ec250d adds absl namespace to debugging/stacktrace.h by Behzad Nouri <bnouri@google.com> - e608018f7faa384d5b202ac0a4c7a0d5166f4d9c Update string_view.h comments to Abseil standards by Tom Manshreck <shreck@google.com> - e884f04d4c648e01ed7dcde2fda80c24e8452047 Exclude strings/ files we are not releasing from OSS univ... by Gennadiy Rozental <rogeeff@google.com> - 3f4c4032ed520f2dd10a81d58ef4f399c001c5cc Strip out eventmanager reference from release. by Gennadiy Rozental <rogeeff@google.com> - fb0f1c204793c3792bad101dbaa734e7c2a35887 Fix copybara strip comments by Gennadiy Rozental <rogeeff@google.com> - 3eaaac942f77c3d41d63d414630403bfd0f6b70c Strip out style guide waivers. by Gennadiy Rozental <rogeeff@google.com> - 020e045058173178b51266b99a2a5dc9ed921960 substitute_test portability | MUST_USE_RESULT cast-to-voi... by Juemin Yang <jueminyang@google.com> - 86c093bf81d80ff537ed5e8b89225ce75a636220 Internal change. by Derek Mauro <dmauro@google.com> - 330375eb952fe78276e75631a28e750d5bfdb198 Prefer absl::FixedTimeZone() over loading "Etc/GMT[-+]<N>". by Abseil Team <absl-team@google.com> - 2e07ebee46a8201adc0dfd2c4ddb3df76e524357 Internal change. by Derek Mauro <dmauro@google.com> - 1f0c8b78c8ebd66f14cdf39fcba9f4c9986dcdca ::absl -> absl by Gennadiy Rozental <rogeeff@google.com> - ad163566d12ea08f1da2c23931eeacfffc564139 Avoid old style loops where possible. by Gennadiy Rozental <rogeeff@google.com> - bce2108818fe57b5617ce0090ddd4f753808f0a1 Update comments in str_cat.h in line with recent changes. by Abseil Team <absl-team@google.com> - cfd593a80f4897256f2ce1ea0be55dc14e3fcad4 Copybara-out gtl aliases. by Gennadiy Rozental <rogeeff@google.com> - 584f1524d717993c1a16093caccd9ed2b1e5409e Fix a warning for Windows/Kokoro time_test.cc. by Daniel Katz <katzdm@google.com> (And 562 more changes) GitOrigin-RevId: 06c8c67f5a564d00696e023060f05a5c34e7e164 Change-Id: I89907a6188fe7de05da400bf49ddfeba242aff8e
7 years ago
7 years ago
} // namespace