Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
00016
00017 #include "gtest/gtest.h"
00018 #include "absl/time/internal/test_util.h"
00019 #include "absl/time/time.h"
00020
00021 namespace cctz = absl::time_internal::cctz;
00022
00023 namespace {
00024
00025 TEST(TimeZone, ValueSemantics) {
00026 absl::TimeZone tz;
00027 absl::TimeZone tz2 = tz;
00028 EXPECT_EQ(tz, tz2);
00029 tz2 = tz;
00030 EXPECT_EQ(tz, tz2);
00031 }
00032
00033 TEST(TimeZone, Equality) {
00034 absl::TimeZone a, b;
00035 EXPECT_EQ(a, b);
00036 EXPECT_EQ(a.name(), b.name());
00037
00038 absl::TimeZone implicit_utc;
00039 absl::TimeZone explicit_utc = absl::UTCTimeZone();
00040 EXPECT_EQ(implicit_utc, explicit_utc);
00041 EXPECT_EQ(implicit_utc.name(), explicit_utc.name());
00042
00043 absl::TimeZone la = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00044 absl::TimeZone nyc = absl::time_internal::LoadTimeZone("America/New_York");
00045 EXPECT_NE(la, nyc);
00046 }
00047
00048 TEST(TimeZone, CCTZConversion) {
00049 const cctz::time_zone cz = cctz::utc_time_zone();
00050 const absl::TimeZone tz(cz);
00051 EXPECT_EQ(cz, cctz::time_zone(tz));
00052 }
00053
00054 TEST(TimeZone, DefaultTimeZones) {
00055 absl::TimeZone tz;
00056 EXPECT_EQ("UTC", absl::TimeZone().name());
00057 EXPECT_EQ("UTC", absl::UTCTimeZone().name());
00058 }
00059
00060 TEST(TimeZone, FixedTimeZone) {
00061 const absl::TimeZone tz = absl::FixedTimeZone(123);
00062 const cctz::time_zone cz = cctz::fixed_time_zone(cctz::seconds(123));
00063 EXPECT_EQ(tz, absl::TimeZone(cz));
00064 }
00065
00066 TEST(TimeZone, LocalTimeZone) {
00067 const absl::TimeZone local_tz = absl::LocalTimeZone();
00068 absl::TimeZone tz = absl::time_internal::LoadTimeZone("localtime");
00069 EXPECT_EQ(tz, local_tz);
00070 }
00071
00072 TEST(TimeZone, NamedTimeZones) {
00073 absl::TimeZone nyc = absl::time_internal::LoadTimeZone("America/New_York");
00074 EXPECT_EQ("America/New_York", nyc.name());
00075 absl::TimeZone syd = absl::time_internal::LoadTimeZone("Australia/Sydney");
00076 EXPECT_EQ("Australia/Sydney", syd.name());
00077 absl::TimeZone fixed = absl::FixedTimeZone((((3 * 60) + 25) * 60) + 45);
00078 EXPECT_EQ("Fixed/UTC+03:25:45", fixed.name());
00079 }
00080
00081 TEST(TimeZone, Failures) {
00082 absl::TimeZone tz = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00083 EXPECT_FALSE(LoadTimeZone("Invalid/TimeZone", &tz));
00084 EXPECT_EQ(absl::UTCTimeZone(), tz);
00085
00086
00087 tz = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00088 EXPECT_FALSE(LoadTimeZone("Invalid/TimeZone", &tz));
00089 EXPECT_EQ(absl::UTCTimeZone(), tz);
00090
00091
00092 tz = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00093 EXPECT_FALSE(LoadTimeZone("", &tz));
00094 EXPECT_EQ(absl::UTCTimeZone(), tz);
00095 }
00096
00097 }