Debian Codegraph @

libstdc++-v3/testsuite/std/time/time_zone/124513.cc

raw
1 // { dg-do run { target c++20 } }
2 // { dg-require-effective-target tzdb }
3 // { dg-require-effective-target cxx11_abi }
4 // { dg-xfail-run-if "no weak override on AIX" { powerpc-ibm-aix* } }
5
6 #include <chrono>
7 #include <fstream>
8 #include <testsuite_hooks.h>
9
10 static bool override_used = false;
11
12 namespace __gnu_cxx
13 {
14 const char* zoneinfo_dir_override() {
15 override_used = true;
16 return "./";
17 }
18 }
19
20 void
21 test_mawson()
22 {
23 using namespace std::chrono;
24
25 std::ofstream("tzdata.zi") << R"(# version test1
26 Z Antarctica/Mawson 0 - -00 1954 F 13
27 6 - %z 2009 O 18 2
28 5 - %z
29 )";
30
31 const auto& db = reload_tzdb();
32 VERIFY( override_used ); // If this fails then XFAIL for the target.
33 VERIFY( db.version == "test1" );
34
35 auto zone = locate_zone("Antarctica/Mawson");
36 auto info = zone->get_info(sys_days(2009y/October/19));
37 VERIFY( info.begin == sys_days(2009y/October/17) + 20h);
38 }
39
40 void
41 test_custom()
42 {
43 using namespace std::chrono;
44
45 std::ofstream("tzdata.zi") << R"(# version test2
46 Z Test/Zomg 3:00:00 - LMT 1990 Mar 1 2
47 4 - DST 1990 Oct 1 2
48 3 - STD 1991 Mar 1 3:30
49 3 1 DST 1991 Oct 1 3:45:01
50 3 - STD 1992 Mar 1 -
51 3 1 DST 1992 Oct 1 -u
52 3 - STD 1993 Mar 1 -s
53 3 2 DST 1993 Oct 1 -s
54 3 - STD
55
56 Z Test/Zoinks 0:00 - LMT 1990 Mar 1 2
57 0:00 1:00 DST 1990 Oct 1 3
58 0:00 - STD 1991 Mar 1 1:30
59 0:00 1:00 DST 1991 Oct 1 3:30
60 0:00 - STD
61 )";
62
63 const auto& db = reload_tzdb();
64 VERIFY( override_used ); // If this fails then XFAIL for the target.
65 VERIFY( db.version == "test2" );
66
67 const auto offset = 3h;
68
69 const time_zone* zone;
70 sys_info info;
71
72 zone = locate_zone("Test/Zomg");
73 info = zone->get_info(sys_days(1990y/June/1));
74 VERIFY( info.begin == sys_days(1990y/March/1) + 2h - 3h);
75 VERIFY( info.end == sys_days(1990y/October/1) + 2h - 4h);
76
77 info = zone->get_info(sys_days(1991y/June/1));
78 VERIFY( info.begin == sys_days(1991y/March/1) + 3h + 30min - 3h);
79 VERIFY( info.end == sys_days(1991y/October/1) + 3h + 45min + 1s - 4h);
80
81 info = zone->get_info(sys_days(1992y/June/1));
82 VERIFY( info.begin == sys_days(1992y/March/1) - 3h);
83 VERIFY( info.end == sys_days(1992y/October/1)); // -u means midnight UTC
84
85 info = zone->get_info(sys_days(1992y/November/1));
86 VERIFY( info.begin == sys_days(1992y/October/1)); // -u means midnight UTC
87 VERIFY( info.end == sys_days(1993y/March/1) - 3h); // -s means midnight STD
88
89 info = zone->get_info(sys_days(1993y/June/1));
90 VERIFY( info.begin == sys_days(1993y/March/1) -3h); // -s means midnight STD
91 VERIFY( info.end == sys_days(1993y/October/1) - 3h);
92
93
94 zone = locate_zone("Test/Zoinks");
95 info = zone->get_info(sys_days(1990y/June/1));
96 VERIFY( info.begin == sys_days(1990y/March/1) + 2h);
97 VERIFY( info.end == sys_days(1990y/October/1) + 3h - 1h);
98
99 info = zone->get_info(sys_days(1991y/June/1));
100 VERIFY( info.begin == sys_days(1991y/March/1) + 1h + 30min);
101 VERIFY( info.end == sys_days(1991y/October/1) + 3h + 30min - 1h);
102
103 info = zone->get_info(sys_days(1992y/June/1));
104 VERIFY( info.begin == sys_days(1991y/October/1) + 3h + 30min - 1h);
105 }
106
107 int main()
108 {
109 test_custom();
110 test_mawson();
111 }