27 #include "gtest/gtest.h" 29 namespace chrono = std::chrono;
32 namespace time_internal {
38 const char*
const kTimeZoneNames[] = {
57 "Africa/Dar_es_Salaam",
64 "Africa/Johannesburg",
98 "America/Argentina/Buenos_Aires",
99 "America/Argentina/Catamarca",
100 "America/Argentina/ComodRivadavia",
101 "America/Argentina/Cordoba",
102 "America/Argentina/Jujuy",
103 "America/Argentina/La_Rioja",
104 "America/Argentina/Mendoza",
105 "America/Argentina/Rio_Gallegos",
106 "America/Argentina/Salta",
107 "America/Argentina/San_Juan",
108 "America/Argentina/San_Luis",
109 "America/Argentina/Tucuman",
110 "America/Argentina/Ushuaia",
116 "America/Bahia_Banderas",
120 "America/Blanc-Sablon",
124 "America/Buenos_Aires",
125 "America/Cambridge_Bay",
126 "America/Campo_Grande",
134 "America/Coral_Harbour",
136 "America/Costa_Rica",
140 "America/Danmarkshavn",
142 "America/Dawson_Creek",
148 "America/El_Salvador",
150 "America/Fort_Nelson",
151 "America/Fort_Wayne",
156 "America/Grand_Turk",
158 "America/Guadeloupe",
164 "America/Hermosillo",
165 "America/Indiana/Indianapolis",
166 "America/Indiana/Knox",
167 "America/Indiana/Marengo",
168 "America/Indiana/Petersburg",
169 "America/Indiana/Tell_City",
170 "America/Indiana/Vevay",
171 "America/Indiana/Vincennes",
172 "America/Indiana/Winamac",
173 "America/Indianapolis",
179 "America/Kentucky/Louisville",
180 "America/Kentucky/Monticello",
182 "America/Kralendijk",
185 "America/Los_Angeles",
186 "America/Louisville",
187 "America/Lower_Princes",
192 "America/Martinique",
198 "America/Metlakatla",
199 "America/Mexico_City",
203 "America/Montevideo",
205 "America/Montserrat",
211 "America/North_Dakota/Beulah",
212 "America/North_Dakota/Center",
213 "America/North_Dakota/New_Salem",
216 "America/Pangnirtung",
217 "America/Paramaribo",
219 "America/Port-au-Prince",
220 "America/Port_of_Spain",
221 "America/Porto_Acre",
222 "America/Porto_Velho",
223 "America/Puerto_Rico",
224 "America/Punta_Arenas",
225 "America/Rainy_River",
226 "America/Rankin_Inlet",
230 "America/Rio_Branco",
232 "America/Santa_Isabel",
235 "America/Santo_Domingo",
237 "America/Scoresbysund",
240 "America/St_Barthelemy",
245 "America/St_Vincent",
246 "America/Swift_Current",
247 "America/Tegucigalpa",
249 "America/Thunder_Bay",
255 "America/Whitehorse",
258 "America/Yellowknife",
261 "Antarctica/DumontDUrville",
262 "Antarctica/Macquarie",
264 "Antarctica/McMurdo",
266 "Antarctica/Rothera",
267 "Antarctica/South_Pole",
271 "Arctic/Longyearbyen",
350 "Asia/Srednekolymsk",
360 "Asia/Ujung_Pandang",
369 "Asia/Yekaterinburg",
374 "Atlantic/Cape_Verde",
377 "Atlantic/Jan_Mayen",
379 "Atlantic/Reykjavik",
380 "Atlantic/South_Georgia",
381 "Atlantic/St_Helena",
384 "Australia/Adelaide",
385 "Australia/Brisbane",
386 "Australia/Broken_Hill",
387 "Australia/Canberra",
393 "Australia/Lindeman",
394 "Australia/Lord_Howe",
395 "Australia/Melbourne",
399 "Australia/Queensland",
402 "Australia/Tasmania",
403 "Australia/Victoria",
405 "Australia/Yancowinna",
416 "Canada/Newfoundland",
418 "Canada/Saskatchewan",
421 "Chile/EasterIsland",
481 "Europe/Isle_of_Man",
484 "Europe/Kaliningrad",
536 "Indian/Antananarivo",
566 "Pacific/Bougainville",
577 "Pacific/Guadalcanal",
581 "Pacific/Kiritimati",
596 "Pacific/Port_Moresby",
635 time_zone LoadZone(
const std::string&
name) {
643 #define ExpectTime(tp, tz, y, m, d, hh, mm, ss, off, isdst, zone) \ 645 time_zone::absolute_lookup al = tz.lookup(tp); \ 646 EXPECT_EQ(y, al.cs.year()); \ 647 EXPECT_EQ(m, al.cs.month()); \ 648 EXPECT_EQ(d, al.cs.day()); \ 649 EXPECT_EQ(hh, al.cs.hour()); \ 650 EXPECT_EQ(mm, al.cs.minute()); \ 651 EXPECT_EQ(ss, al.cs.second()); \ 652 EXPECT_EQ(off, al.offset); \ 653 EXPECT_TRUE(isdst == al.is_dst); \ 662 int VersionCmp(time_zone tz,
const std::string& target) {
663 std::string
version = tz.version();
664 if (version.empty() && !target.empty())
return 1;
665 return version.compare(target);
670 #if !defined(__EMSCRIPTEN__) 671 TEST(TimeZones, LoadZonesConcurrently) {
672 std::promise<void> ready_promise;
673 std::shared_future<void> ready_future(ready_promise.get_future());
674 auto load_zones = [ready_future](std::promise<void>* started,
675 std::set<std::string>* failures) {
676 started->set_value();
678 for (
const char*
const* np = kTimeZoneNames; *np !=
nullptr; ++np) {
679 std::string zone = *np;
682 EXPECT_EQ(zone, tz.
name());
684 failures->insert(zone);
689 const std::size_t n_threads = 128;
690 std::vector<std::thread> threads;
691 std::vector<std::set<std::string>> thread_failures(n_threads);
692 for (std::size_t
i = 0;
i != n_threads; ++
i) {
693 std::promise<void> started;
694 threads.emplace_back(load_zones, &started, &thread_failures[
i]);
695 started.get_future().wait();
697 ready_promise.set_value();
698 for (
auto& thread : threads) {
704 #if defined(__ANDROID__) 708 const std::size_t max_failures = 20;
710 const std::size_t max_failures = 3;
712 std::set<std::string> failures;
713 for (
const auto& thread_failure : thread_failures) {
714 failures.insert(thread_failure.begin(), thread_failure.end());
716 EXPECT_LE(failures.size(), max_failures) << testing::PrintToString(failures);
722 EXPECT_EQ(
"UTC", utc.
name());
723 const time_zone nyc = LoadZone(
"America/New_York");
724 EXPECT_EQ(
"America/New_York", nyc.name());
725 const time_zone syd = LoadZone(
"Australia/Sydney");
726 EXPECT_EQ(
"Australia/Sydney", syd.name());
728 EXPECT_EQ(
"UTC", fixed0.name());
731 EXPECT_EQ(
"Fixed/UTC+03:25:45", fixed_pos.name());
734 EXPECT_EQ(
"Fixed/UTC-12:34:56", fixed_neg.name());
741 tz = LoadZone(
"America/Los_Angeles");
743 EXPECT_EQ(chrono::system_clock::from_time_t(0),
747 tz = LoadZone(
"America/Los_Angeles");
749 EXPECT_EQ(chrono::system_clock::from_time_t(0),
753 tz = LoadZone(
"America/Los_Angeles");
755 EXPECT_EQ(chrono::system_clock::from_time_t(0),
767 EXPECT_EQ(implicit_utc, explicit_utc);
768 EXPECT_EQ(implicit_utc.name(), explicit_utc.
name());
771 EXPECT_EQ(fixed_zero, LoadZone(fixed_zero.name()));
772 EXPECT_EQ(fixed_zero, explicit_utc);
774 const time_zone fixed_utc = LoadZone(
"Fixed/UTC+00:00:00");
775 EXPECT_EQ(fixed_utc, LoadZone(fixed_utc.
name()));
776 EXPECT_EQ(fixed_utc, explicit_utc);
780 EXPECT_EQ(fixed_pos, LoadZone(fixed_pos.
name()));
781 EXPECT_NE(fixed_pos, explicit_utc);
784 EXPECT_EQ(fixed_neg, LoadZone(fixed_neg.
name()));
785 EXPECT_NE(fixed_neg, explicit_utc);
788 EXPECT_EQ(fixed_lim, LoadZone(fixed_lim.
name()));
789 EXPECT_NE(fixed_lim, explicit_utc);
792 EXPECT_EQ(fixed_ovfl, LoadZone(fixed_ovfl.
name()));
793 EXPECT_EQ(fixed_ovfl, explicit_utc);
799 EXPECT_EQ(local, LoadZone(local.
name()));
801 time_zone la = LoadZone(
"America/Los_Angeles");
802 time_zone nyc = LoadZone(
"America/New_York");
806 TEST(StdChronoTimePoint, TimeTAlignment) {
810 chrono::system_clock::from_time_t(0);
811 EXPECT_EQ(chrono::system_clock::time_point::duration::zero(),
815 TEST(BreakTime, TimePointResolution) {
817 const auto t0 = chrono::system_clock::from_time_t(0);
819 ExpectTime(chrono::time_point_cast<chrono::nanoseconds>(t0), utc,
820 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
821 ExpectTime(chrono::time_point_cast<chrono::microseconds>(t0), utc,
822 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
823 ExpectTime(chrono::time_point_cast<chrono::milliseconds>(t0), utc,
824 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
825 ExpectTime(chrono::time_point_cast<chrono::seconds>(t0), utc,
826 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
827 ExpectTime(chrono::time_point_cast<absl::time_internal::cctz::seconds>(t0), utc,
828 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
829 ExpectTime(chrono::time_point_cast<chrono::minutes>(t0), utc,
830 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
831 ExpectTime(chrono::time_point_cast<chrono::hours>(t0), utc,
832 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
835 TEST(BreakTime, LocalTimeInUTC) {
837 const auto tp = chrono::system_clock::from_time_t(0);
838 ExpectTime(tp, tz, 1970, 1, 1, 0, 0, 0, 0,
false,
"UTC");
842 TEST(BreakTime, LocalTimeInUTCUnaligned) {
845 chrono::system_clock::from_time_t(0) - chrono::milliseconds(500);
846 ExpectTime(tp, tz, 1969, 12, 31, 23, 59, 59, 0,
false,
"UTC");
850 TEST(BreakTime, LocalTimePosix) {
853 const auto tp = chrono::system_clock::from_time_t(536457599);
854 ExpectTime(tp, tz, 1986, 12, 31, 23, 59, 59, 0,
false,
"UTC");
858 TEST(TimeZoneImpl, LocalTimeInFixed) {
862 const auto tp = chrono::system_clock::from_time_t(0);
863 ExpectTime(tp, tz, 1969, 12, 31, 15, 26, 13, offset.count(),
false,
868 TEST(BreakTime, LocalTimeInNewYork) {
869 const time_zone tz = LoadZone(
"America/New_York");
870 const auto tp = chrono::system_clock::from_time_t(45);
871 ExpectTime(tp, tz, 1969, 12, 31, 19, 0, 45, -5 * 60 * 60,
false,
"EST");
875 TEST(BreakTime, LocalTimeInMTV) {
876 const time_zone tz = LoadZone(
"America/Los_Angeles");
877 const auto tp = chrono::system_clock::from_time_t(1380855729);
878 ExpectTime(tp, tz, 2013, 10, 3, 20, 2, 9, -7 * 60 * 60,
true,
"PDT");
882 TEST(BreakTime, LocalTimeInSydney) {
883 const time_zone tz = LoadZone(
"Australia/Sydney");
884 const auto tp = chrono::system_clock::from_time_t(90);
885 ExpectTime(tp, tz, 1970, 1, 1, 10, 1, 30, 10 * 60 * 60,
false,
"AEST");
889 TEST(MakeTime, TimePointResolution) {
893 EXPECT_EQ(
"04:05",
format(
"%M:%E*S", tp_ns, utc));
896 EXPECT_EQ(
"04:05",
format(
"%M:%E*S", tp_us, utc));
899 EXPECT_EQ(
"04:05",
format(
"%M:%E*S", tp_ms, utc));
902 EXPECT_EQ(
"04:05",
format(
"%M:%E*S", tp_s, utc));
905 EXPECT_EQ(
"04:05",
format(
"%M:%E*S", tp_s64, utc));
911 chrono::time_point_cast<chrono::minutes>(
913 EXPECT_EQ(
"04:00",
format(
"%M:%E*S", tp_m, utc));
915 chrono::time_point_cast<chrono::hours>(
917 EXPECT_EQ(
"00:00",
format(
"%M:%E*S", tp_h, utc));
920 TEST(MakeTime, Normalization) {
921 const time_zone tz = LoadZone(
"America/New_York");
923 EXPECT_EQ(chrono::system_clock::from_time_t(1234567890), tp);
934 TEST(MakeTime, SysSecondsLimits) {
935 const char RFC3339[] =
"%Y-%m-%dT%H:%M:%S%Ez";
943 EXPECT_EQ(
"292277026596-12-04T15:30:06+00:00",
format(RFC3339, tp, utc));
945 EXPECT_EQ(
"292277026596-12-04T15:30:07+00:00",
format(RFC3339, tp, utc));
954 EXPECT_EQ(
"292277026596-12-05T05:30:07+14:00",
format(RFC3339, tp, east));
963 EXPECT_EQ(
"292277026596-12-04T01:30:07-14:00",
format(RFC3339, tp, west));
972 EXPECT_EQ(
"-292277022657-01-27T08:29:53+00:00",
format(RFC3339, tp, utc));
974 EXPECT_EQ(
"-292277022657-01-27T08:29:52+00:00",
format(RFC3339, tp, utc));
983 EXPECT_EQ(
"-292277022657-01-27T22:29:52+14:00",
format(RFC3339, tp, east));
992 EXPECT_EQ(
"-292277022657-01-26T18:29:52-14:00",
format(RFC3339, tp, west));
1000 if (
sizeof(std::time_t) >= 8) {
1003 #if defined(_WIN32) || defined(_WIN64) 1006 const time_zone utc = LoadZone(
"libc:UTC");
1007 const year_t max_tm_year =
year_t{std::numeric_limits<int>::max()} + 1900;
1009 EXPECT_EQ(
"2147485547-12-31T23:59:59+00:00",
format(RFC3339, tp, utc));
1010 const year_t min_tm_year =
year_t{std::numeric_limits<int>::min()} + 1900;
1012 EXPECT_EQ(
"-2147481748-01-01T00:00:00+00:00",
format(RFC3339, tp, utc));
1024 #if defined(__linux__) && !defined(__ANDROID__) 1025 const char*
const ep = getenv(
"TZ");
1026 std::string tz_name = (ep !=
nullptr) ? ep :
"";
1027 for (
const char*
const* np = kTimeZoneNames; *np !=
nullptr; ++np) {
1028 ASSERT_EQ(0, setenv(
"TZ", *np, 1));
1030 const auto lc = LoadZone(
"libc:localtime");
1033 zi.next_transition(tp, &trans);
1034 tp = zi.lookup(trans.
to).trans) {
1035 const auto fcl = zi.lookup(trans.
from);
1036 const auto tcl = zi.lookup(trans.
to);
1041 ASSERT_EQ(trans.
from, trans.
to);
1042 const auto trans = fcl.trans;
1043 const auto tal = zi.lookup(trans);
1045 const auto pal = zi.lookup(tprev);
1046 if (pal.is_dst == tal.is_dst) {
1047 ASSERT_STRNE(pal.abbr, tal.abbr);
1058 if (cs.
year() > 2037)
break;
1059 const auto cl_zi = zi.lookup(cs);
1060 if (zi.lookup(cl_zi.pre).is_dst == zi.lookup(cl_zi.post).is_dst) {
1076 const std::string tzname = *np;
1077 if (tzname ==
"Africa/Casablanca" || tzname ==
"Africa/El_Aaiun") {
1084 const auto cl_lc = lc.lookup(cs);
1085 SCOPED_TRACE(testing::Message() <<
"For " << cs <<
" in " << *np);
1086 EXPECT_EQ(cl_zi.kind, cl_lc.kind);
1087 EXPECT_EQ(cl_zi.pre, cl_lc.pre);
1088 EXPECT_EQ(cl_zi.trans, cl_lc.trans);
1089 EXPECT_EQ(cl_zi.post, cl_lc.post);
1092 if (ep ==
nullptr) {
1093 ASSERT_EQ(0, unsetenv(
"TZ"));
1095 ASSERT_EQ(0, setenv(
"TZ", tz_name.c_str(), 1));
1105 EXPECT_FALSE(tz.next_transition(tp, &trans));
1108 EXPECT_FALSE(tz.next_transition(tp, &trans));
1116 EXPECT_FALSE(tz.prev_transition(tp, &trans));
1119 EXPECT_FALSE(tz.prev_transition(tp, &trans));
1122 TEST(NextTransition, AmericaNewYork) {
1123 const auto tz = LoadZone(
"America/New_York");
1127 EXPECT_TRUE(tz.next_transition(tp, &trans));
1132 EXPECT_FALSE(tz.next_transition(tp, &trans));
1135 EXPECT_TRUE(tz.next_transition(tp, &trans));
1146 TEST(PrevTransition, AmericaNewYork) {
1147 const auto tz = LoadZone(
"America/New_York");
1151 EXPECT_TRUE(tz.prev_transition(tp, &trans));
1156 EXPECT_FALSE(tz.prev_transition(tp, &trans));
1159 EXPECT_TRUE(tz.prev_transition(tp, &trans));
1163 TEST(TimeZoneEdgeCase, AmericaNewYork) {
1164 const time_zone tz = LoadZone(
"America/New_York");
1168 ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -5 * 3600,
false,
"EST");
1170 ExpectTime(tp, tz, 2013, 3, 10, 3, 0, 0, -4 * 3600,
true,
"EDT");
1174 ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -4 * 3600,
true,
"EDT");
1176 ExpectTime(tp, tz, 2013, 11, 3, 1, 0, 0, -5 * 3600,
false,
"EST");
1179 TEST(TimeZoneEdgeCase, AmericaLosAngeles) {
1180 const time_zone tz = LoadZone(
"America/Los_Angeles");
1184 ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -8 * 3600,
false,
"PST");
1186 ExpectTime(tp, tz, 2013, 3, 10, 3, 0, 0, -7 * 3600,
true,
"PDT");
1190 ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -7 * 3600,
true,
"PDT");
1192 ExpectTime(tp, tz, 2013, 11, 3, 1, 0, 0, -8 * 3600,
false,
"PST");
1195 TEST(TimeZoneEdgeCase, ArizonaNoTransition) {
1196 const time_zone tz = LoadZone(
"America/Phoenix");
1200 ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -7 * 3600,
false,
"MST");
1202 ExpectTime(tp, tz, 2013, 3, 10, 2, 0, 0, -7 * 3600,
false,
"MST");
1206 ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -7 * 3600,
false,
"MST");
1208 ExpectTime(tp, tz, 2013, 11, 3, 2, 0, 0, -7 * 3600,
false,
"MST");
1211 TEST(TimeZoneEdgeCase, AsiaKathmandu) {
1212 const time_zone tz = LoadZone(
"Asia/Kathmandu");
1219 ExpectTime(tp, tz, 1985, 12, 31, 23, 59, 59, 5.5 * 3600,
false,
"+0530");
1221 ExpectTime(tp, tz, 1986, 1, 1, 0, 15, 0, 5.75 * 3600,
false,
"+0545");
1224 TEST(TimeZoneEdgeCase, PacificChatham) {
1225 const time_zone tz = LoadZone(
"Pacific/Chatham");
1232 ExpectTime(tp, tz, 2013, 4, 7, 3, 44, 59, 13.75 * 3600,
true,
"+1345");
1234 ExpectTime(tp, tz, 2013, 4, 7, 2, 45, 0, 12.75 * 3600,
false,
"+1245");
1239 ExpectTime(tp, tz, 2013, 9, 29, 2, 44, 59, 12.75 * 3600,
false,
"+1245");
1241 ExpectTime(tp, tz, 2013, 9, 29, 3, 45, 0, 13.75 * 3600,
true,
"+1345");
1244 TEST(TimeZoneEdgeCase, AustraliaLordHowe) {
1245 const time_zone tz = LoadZone(
"Australia/Lord_Howe");
1252 ExpectTime(tp, tz, 2013, 4, 7, 1, 59, 59, 11 * 3600,
true,
"+11");
1254 ExpectTime(tp, tz, 2013, 4, 7, 1, 30, 0, 10.5 * 3600,
false,
"+1030");
1259 ExpectTime(tp, tz, 2013, 10, 6, 1, 59, 59, 10.5 * 3600,
false,
"+1030");
1261 ExpectTime(tp, tz, 2013, 10, 6, 2, 30, 0, 11 * 3600,
true,
"+11");
1264 TEST(TimeZoneEdgeCase, PacificApia) {
1265 const time_zone tz = LoadZone(
"Pacific/Apia");
1276 ExpectTime(tp, tz, 2011, 12, 29, 23, 59, 59, -10 * 3600,
true,
"-10");
1279 ExpectTime(tp, tz, 2011, 12, 31, 0, 0, 0, 14 * 3600,
true,
"+14");
1283 TEST(TimeZoneEdgeCase, AfricaCairo) {
1284 const time_zone tz = LoadZone(
"Africa/Cairo");
1286 if (VersionCmp(tz,
"2014c") >= 0) {
1292 ExpectTime(tp, tz, 2014, 5, 15, 23, 59, 59, 2 * 3600,
false,
"EET");
1294 ExpectTime(tp, tz, 2014, 5, 16, 1, 0, 0, 3 * 3600,
true,
"EEST");
1298 TEST(TimeZoneEdgeCase, AfricaMonrovia) {
1299 const time_zone tz = LoadZone(
"Africa/Monrovia");
1301 if (VersionCmp(tz,
"2017b") >= 0) {
1307 ExpectTime(tp, tz, 1972, 1, 6, 23, 59, 59, -44.5 * 60,
false,
"MMT");
1309 ExpectTime(tp, tz, 1972, 1, 7, 0, 44, 30, 0 * 60,
false,
"GMT");
1313 TEST(TimeZoneEdgeCase, AmericaJamaica) {
1319 const time_zone tz = LoadZone(
"America/Jamaica");
1322 if (!tz.
version().empty() && VersionCmp(tz,
"2018d") >= 0) {
1328 ExpectTime(tp, tz, 1889, 12, 31, 0, 0, 0, -18430,
false,
1335 ExpectTime(tp, tz, 1889, 12, 31, 23, 59, 59, -18430,
false,
1338 ExpectTime(tp, tz, 1890, 1, 1, 0, 0, 0, -18430,
false,
"KMT");
1345 ExpectTime(tp, tz, 1983, 10, 30, 1, 59, 59, -4 * 3600,
true,
"EDT");
1347 ExpectTime(tp, tz, 1983, 10, 30, 1, 0, 0, -5 * 3600,
false,
"EST");
1351 ExpectTime(tp, tz, 1983, 12, 31, 23, 59, 59, -5 * 3600,
false,
"EST");
1360 ExpectTime(tp, tz, 1977, 1, 1, 0, 0, 0, 0,
false,
"WET");
1366 ExpectTime(tp, tz, 1977, 4, 3, 0, 59, 59, 0,
false,
"WET");
1368 ExpectTime(tp, tz, 1977, 4, 3, 2, 0, 0, 1 * 3600,
true,
"WEST");
1373 ExpectTime(cl1.
pre, tz, 1977, 4, 3, 2, 15, 0, 1 * 3600,
true,
"WEST");
1374 ExpectTime(cl1.
trans, tz, 1977, 4, 3, 2, 0, 0, 1 * 3600,
true,
"WEST");
1375 ExpectTime(cl1.
post, tz, 1977, 4, 3, 0, 15, 0, 0 * 3600,
false,
"WET");
1380 ExpectTime(cl2.
pre, tz, 1978, 4, 2, 2, 15, 0, 1 * 3600,
true,
"WEST");
1381 ExpectTime(cl2.
trans, tz, 1978, 4, 2, 2, 0, 0, 1 * 3600,
true,
"WEST");
1382 ExpectTime(cl2.
post, tz, 1978, 4, 2, 0, 15, 0, 0 * 3600,
false,
"WET");
1385 TEST(TimeZoneEdgeCase, FixedOffsets) {
1386 const time_zone gmtm5 = LoadZone(
"Etc/GMT+5");
1388 ExpectTime(tp, gmtm5, 1970, 1, 1, 0, 0, 0, -5 * 3600,
false,
"-05");
1389 EXPECT_EQ(chrono::system_clock::from_time_t(5 * 3600), tp);
1391 const time_zone gmtp5 = LoadZone(
"Etc/GMT-5");
1393 ExpectTime(tp, gmtp5, 1970, 1, 1, 0, 0, 0, 5 * 3600,
false,
"+05");
1394 EXPECT_EQ(chrono::system_clock::from_time_t(-5 * 3600), tp);
1397 TEST(TimeZoneEdgeCase, NegativeYear) {
1401 ExpectTime(tp, tz, 0, 1, 1, 0, 0, 0, 0 * 3600,
false,
"UTC");
1404 ExpectTime(tp, tz, -1, 12, 31, 23, 59, 59, 0 * 3600,
false,
"UTC");
1408 TEST(TimeZoneEdgeCase, UTC32bitLimit) {
1416 ExpectTime(tp, tz, 2038, 1, 19, 3, 14, 7, 0 * 3600,
false,
"UTC");
1418 ExpectTime(tp, tz, 2038, 1, 19, 3, 14, 8, 0 * 3600,
false,
"UTC");
1421 TEST(TimeZoneEdgeCase, UTC5DigitYear) {
1429 ExpectTime(tp, tz, 9999, 12, 31, 23, 59, 59, 0 * 3600,
false,
"UTC");
1431 ExpectTime(tp, tz, 10000, 1, 1, 0, 0, 0, 0 * 3600,
false,
"UTC");
time_point< seconds > post
time_point< seconds > trans
CONSTEXPR_F int get_yearday(const civil_day &cd) noexcept
#define ExpectTime(tp, tz, y, m, d, hh, mm, ss, off, isdst, zone)
time_zone fixed_time_zone(const seconds &offset)
std::string format(const std::string &fmt, const time_point< D > &tp, const time_zone &tz)
CONSTEXPR_F weekday get_weekday(const civil_day &cd) noexcept
std::chrono::duration< std::int_fast64_t > seconds
detail::civil_day civil_day
static CONSTEXPR_F civil_time() max()
static CONSTEXPR_F civil_time() min()
CONSTEXPR_M year_t year() const noexcept
time_zone local_time_zone()
absolute_lookup lookup(const time_point< seconds > &tp) const
std::string version() const
time_point< seconds > pre
enum absl::time_internal::cctz::time_zone::civil_lookup::civil_kind kind
std::chrono::time_point< std::chrono::system_clock, D > time_point
time_zone utc_time_zone()
TEST(CivilTime, DefaultConstruction)
bool load_time_zone(const std::string &name, time_zone *tz)
civil_second convert(const time_point< D > &tp, const time_zone &tz)
detail::civil_second civil_second