summaryrefslogtreecommitdiff
path: root/absl/time/time_test.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2018-10-15 11:30:24 -0700
committerGravatar Xiaoyi Zhang <zhangxy988@gmail.com>2018-10-15 15:32:46 -0400
commit5b70a8910b2e6fb0ce5193a41873139a126d2f7f (patch)
tree1a4a99b5c877f0b69bd8756ea1518dd16f09dd2b /absl/time/time_test.cc
parenta00bdd176d66ef0b417d9576052a19091fbdf891 (diff)
Export of internal Abseil changes.
-- f4e870453d02106c2685e0461816469a4704ad25 by Abseil Team <absl-team@google.com>: Expose TimeZone::NextTransition() and PrevTransition() now that we have absl::CivilSecond support in time.h. Note that these are for informational purposes only. General time code should not care when offset changes occur. PiperOrigin-RevId: 217177292 -- cfadd275c7333f7c27c4d682b9d167010d874e69 by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 217153577 -- 6ff5b8c61a1239b9c0478a7c62bcd2844b310307 by Jon Cohen <cohenjon@google.com>: Fix code examples in hash_testing.h. Includes random clang-format changes. PiperOrigin-RevId: 216898995 -- de124129d27f4627dabe193a10bf106a11783fba by Shaindel Schwartz <shaindel@google.com>: Add contribution guidelines describing how we decide whether to include an API in Abseil. PiperOrigin-RevId: 216886943 GitOrigin-RevId: f4e870453d02106c2685e0461816469a4704ad25 Change-Id: Ib9c6706f5bf931b71c0357bf1342053a3bee8ff7
Diffstat (limited to 'absl/time/time_test.cc')
-rw-r--r--absl/time/time_test.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/absl/time/time_test.cc b/absl/time/time_test.cc
index feca4587..4d710709 100644
--- a/absl/time/time_test.cc
+++ b/absl/time/time_test.cc
@@ -1135,4 +1135,67 @@ TEST(Time, LegacyDateTime) {
EXPECT_EQ("2014-10-29 22:58:59", absl::FormatTime(ymdhms, t, utc));
}
+TEST(Time, NextTransitionUTC) {
+ const auto tz = absl::UTCTimeZone();
+ absl::TimeZone::CivilTransition trans;
+
+ auto t = absl::InfinitePast();
+ EXPECT_FALSE(tz.NextTransition(t, &trans));
+
+ t = absl::InfiniteFuture();
+ EXPECT_FALSE(tz.NextTransition(t, &trans));
+}
+
+TEST(Time, PrevTransitionUTC) {
+ const auto tz = absl::UTCTimeZone();
+ absl::TimeZone::CivilTransition trans;
+
+ auto t = absl::InfiniteFuture();
+ EXPECT_FALSE(tz.PrevTransition(t, &trans));
+
+ t = absl::InfinitePast();
+ EXPECT_FALSE(tz.PrevTransition(t, &trans));
+}
+
+TEST(Time, NextTransitionNYC) {
+ const auto tz = absl::time_internal::LoadTimeZone("America/New_York");
+ absl::TimeZone::CivilTransition trans;
+
+ auto t = absl::FromCivil(absl::CivilSecond(2018, 6, 30, 0, 0, 0), tz);
+ EXPECT_TRUE(tz.NextTransition(t, &trans));
+ EXPECT_EQ(absl::CivilSecond(2018, 11, 4, 2, 0, 0), trans.from);
+ EXPECT_EQ(absl::CivilSecond(2018, 11, 4, 1, 0, 0), trans.to);
+
+ t = absl::InfiniteFuture();
+ EXPECT_FALSE(tz.NextTransition(t, &trans));
+
+ t = absl::InfinitePast();
+ EXPECT_TRUE(tz.NextTransition(t, &trans));
+ if (trans.from == absl::CivilSecond(1918, 03, 31, 2, 0, 0)) {
+ // It looks like the tzdata is only 32 bit (probably macOS),
+ // which bottoms out at 1901-12-13T20:45:52+00:00.
+ EXPECT_EQ(absl::CivilSecond(1918, 3, 31, 3, 0, 0), trans.to);
+ } else {
+ EXPECT_EQ(absl::CivilSecond(1883, 11, 18, 12, 3, 58), trans.from);
+ EXPECT_EQ(absl::CivilSecond(1883, 11, 18, 12, 0, 0), trans.to);
+ }
+}
+
+TEST(Time, PrevTransitionNYC) {
+ const auto tz = absl::time_internal::LoadTimeZone("America/New_York");
+ absl::TimeZone::CivilTransition trans;
+
+ auto t = absl::FromCivil(absl::CivilSecond(2018, 6, 30, 0, 0, 0), tz);
+ EXPECT_TRUE(tz.PrevTransition(t, &trans));
+ EXPECT_EQ(absl::CivilSecond(2018, 3, 11, 2, 0, 0), trans.from);
+ EXPECT_EQ(absl::CivilSecond(2018, 3, 11, 3, 0, 0), trans.to);
+
+ t = absl::InfinitePast();
+ EXPECT_FALSE(tz.PrevTransition(t, &trans));
+
+ t = absl::InfiniteFuture();
+ EXPECT_TRUE(tz.PrevTransition(t, &trans));
+ // We have a transition but we don't know which one.
+}
+
} // namespace