Debian Codegraph @

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

raw
1 // { dg-do run { target c++20 } }
2 // { dg-require-effective-target tzdb }
3
4 #include <chrono>
5 #include <testsuite_hooks.h>
6
7 void
8 test_zurich()
9 {
10 using namespace std::chrono;
11
12 const time_zone* const tz = locate_zone("Europe/Zurich");
13
14 {
15 sys_days d = 1853y/July/16; // On this date ...
16 auto offset = 34min + 8s; // ... local time is this far ahead of UTC,
17 auto t = d - offset; // so LMT to BMT transition is at this time.
18
19 auto info = tz->get_info(t - 1s);
20 VERIFY( info.offset == offset );
21 VERIFY( info.abbrev == "LMT" );
22
23 info = tz->get_info(t);
24 VERIFY( info.offset == (29min + 46s) );
25 VERIFY( info.abbrev == "BMT" );
26
27 info = tz->get_info(t + 1s);
28 VERIFY( info.offset == (29min + 46s) );
29 VERIFY( info.abbrev == "BMT" );
30
31 info = tz->get_info(t + 0.001s);
32 VERIFY( info.offset == (29min + 46s) );
33 VERIFY( info.abbrev == "BMT" );
34 }
35
36 {
37 sys_days d = 1894y/June/1;
38 auto offset = 29min + 46s;
39 auto t = d - offset;
40
41 auto info = tz->get_info(t - 1s);
42 VERIFY( info.offset == offset );
43 VERIFY( info.abbrev == "BMT" );
44
45 info = tz->get_info(t);
46 VERIFY( info.offset == 1h );
47 VERIFY( info.abbrev == "CET" );
48 }
49
50 {
51 sys_days d = 1941y/May/Monday[1];
52
53 auto info = tz->get_info(d - 1s);
54 VERIFY( info.offset == 1h );
55 VERIFY( info.abbrev == "CET" );
56
57 // CEST daylight savings time starts at 1am local time (UTC+1).
58 info = tz->get_info(d);
59 VERIFY( info.offset == 2h );
60 VERIFY( info.abbrev == "CEST" );
61 }
62
63 {
64 sys_days d = 1941y/October/Monday[1];
65
66 auto info = tz->get_info(d - 1s);
67 VERIFY( info.offset == 2h );
68 VERIFY( info.abbrev == "CEST" );
69
70 // CET standard time starts at 2am local time (UTC+2).
71 info = tz->get_info(d);
72 VERIFY( info.offset == 1h );
73 VERIFY( info.abbrev == "CET" );
74 }
75
76 {
77 sys_days d = 1942y/May/Monday[1];
78
79 auto info = tz->get_info(d - 1s);
80 VERIFY( info.offset == 1h );
81 VERIFY( info.abbrev == "CET" );
82
83 // CEST daylight savings time starts at 1am local time (UTC+1).
84 info = tz->get_info(d);
85 VERIFY( info.offset == 2h );
86 VERIFY( info.abbrev == "CEST" );
87 }
88
89 {
90 sys_days d = 1942y/October/Monday[1];
91
92 auto info = tz->get_info(d - 1s);
93 VERIFY( info.offset == 2h );
94 VERIFY( info.abbrev == "CEST" );
95
96 // CET standard time starts at 2am local time (UTC+2).
97 info = tz->get_info(d);
98 VERIFY( info.offset == 1h );
99 VERIFY( info.abbrev == "CET" );
100 }
101
102 {
103 sys_days d = 1943y/May/Monday[1];
104
105 // No daylight savings from 1943 until 1981.
106 auto info = tz->get_info(d);
107 VERIFY( info.offset == 1h );
108 VERIFY( info.abbrev == "CET" );
109
110 info = tz->get_info(d + days(60));
111 VERIFY( info.offset == 1h );
112 VERIFY( info.abbrev == "CET" );
113
114 info = tz->get_info(d + years(10));
115 VERIFY( info.offset == 1h );
116 VERIFY( info.abbrev == "CET" );
117
118 info = tz->get_info(sys_days(1979y/June/3));
119 VERIFY( info.offset == 1h );
120 VERIFY( info.abbrev == "CET" );
121 }
122
123 {
124 // Switzerland uses EU rules from 1981
125 sys_days d = 1981y/March/Sunday[last];
126
127 auto info = tz->get_info(d);
128 VERIFY( info.offset == 1h );
129 VERIFY( info.abbrev == "CET" );
130
131 info = tz->get_info(d + 59min + 59s);
132 VERIFY( info.offset == 1h );
133 VERIFY( info.abbrev == "CET" );
134
135 // CEST begins at 1am UTC
136 info = tz->get_info(d + 1h);
137 VERIFY( info.offset == 2h );
138 VERIFY( info.abbrev == "CEST" );
139 }
140
141 {
142 sys_days d = 1981y/September/Sunday[last];
143
144 auto info = tz->get_info(d + 59min + 59s);
145 VERIFY( info.offset == 2h );
146 VERIFY( info.abbrev == "CEST" );
147
148 // CEST ends at 1am UTC
149 info = tz->get_info(d + 1h);
150 VERIFY( info.offset == 1h );
151 VERIFY( info.abbrev == "CET" );
152 }
153
154 {
155 sys_days d = 1994y/September/Sunday[last];
156
157 auto info = tz->get_info(d + 59min + 59s);
158 VERIFY( info.offset == 2h );
159 VERIFY( info.abbrev == "CEST" );
160
161 // CEST ends at 1am UTC
162 info = tz->get_info(d + 1h);
163 VERIFY( info.offset == 1h );
164 VERIFY( info.abbrev == "CET" );
165
166 d = 1995y/September/Sunday[last];
167 info = tz->get_info(d + 59min + 59s);
168 VERIFY( info.offset == 2h );
169 VERIFY( info.abbrev == "CEST" );
170
171 // CEST ends at 1am UTC
172 info = tz->get_info(d + 1h);
173 VERIFY( info.offset == 1h );
174 VERIFY( info.abbrev == "CET" );
175
176 d = 1996y/September/Sunday[last];
177 // CEST ends in October since 1996
178 info = tz->get_info(d + 1h);
179 VERIFY( info.offset == 2h );
180 VERIFY( info.abbrev == "CEST" );
181
182 d = 1996y/October/Sunday[last];
183 // CEST ends at 1am UTC
184 info = tz->get_info(d + 1h);
185 VERIFY( info.offset == 1h );
186 VERIFY( info.abbrev == "CET" );
187 }
188 }
189
190 void
191 test_iterate()
192 {
193 using namespace std::chrono;
194 auto tz = locate_zone("Europe/Zurich");
195 sys_seconds start(sys_days(1850y/January/1));
196 const sys_seconds finish(sys_days(1982y/January/1));
197 long count = 0;
198 do
199 {
200 VERIFY(++count < 100); // Fail if we get stuck in a loop.
201 auto info = tz->get_info(start);
202 start = info.end;
203 } while (start < finish);
204
205 VERIFY(count == 10); // Would be 9 if identical adjacent sys_info get merged.
206 }
207
208 void
209 test_shanghai()
210 {
211 using namespace std::chrono;
212 auto tz = locate_zone("Asia/Shanghai");
213 sys_info info = tz->get_info(sys_days(1949y/January/1));
214 VERIFY( info.abbrev == "CST" );
215 }
216
217 int main()
218 {
219 test_zurich();
220 test_iterate();
221 test_shanghai();
222 }