NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
tz_private.h
Go to the documentation of this file.
1#ifndef TZ_PRIVATE_H
2#define TZ_PRIVATE_H
3
4// The MIT License (MIT)
5//
6// Copyright (c) 2015, 2016 Howard Hinnant
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in all
16// copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24// SOFTWARE.
25//
26// Our apologies. When the previous paragraph was written, lowercase had not yet
27// been invented (that would involve another several millennia of evolution).
28// We did not mean to shout.
29
30#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
31#include "tz.h"
32#else
33#include "date.h"
34#include <vector>
35#endif
36
37namespace date
38{
39
40namespace detail
41{
42
43#if !USE_OS_TZDB
44
45enum class tz {utc, local, standard};
46
47//forward declare to avoid warnings in gcc 6.2
48class MonthDayTime;
49std::istream& operator>>(std::istream& is, MonthDayTime& x);
50std::ostream& operator<<(std::ostream& os, const MonthDayTime& x);
51
52
54{
55private:
56 struct pair
57 {
58#if defined(_MSC_VER) && (_MSC_VER < 1900)
59 pair() : month_day_(date::jan / 1), weekday_(0U) {}
60
63#endif
64
67 };
68
70
72
73#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
74 union U
75#else
76 struct U
77#endif
78 {
82
83#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
84 U() : month_day_{date::jan/1} {}
85#else
86 U() :
89 {}
90
91#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
92
93 U& operator=(const date::month_day& x);
95 U& operator=(const pair& x);
96 } u;
97
98 std::chrono::hours h_{0};
99 std::chrono::minutes m_{0};
100 std::chrono::seconds s_{0};
102
103public:
104 MonthDayTime() = default;
105 MonthDayTime(local_seconds tp, tz timezone);
106 MonthDayTime(const date::month_day& md, tz timezone);
107
108 date::day day() const;
109 date::month month() const;
110 tz zone() const {return zone_;}
111
112 void canonicalize(date::year y);
113
115 to_sys(date::year y, std::chrono::seconds offset, std::chrono::seconds save) const;
117
119 int compare(date::year y, const MonthDayTime& x, date::year yx,
120 std::chrono::seconds offset, std::chrono::minutes prev_save) const;
121
122 friend std::istream& operator>>(std::istream& is, MonthDayTime& x);
123 friend std::ostream& operator<<(std::ostream& os, const MonthDayTime& x);
124};
125
126// A Rule specifies one or more set of datetimes without using an offset.
127// Multiple dates are specified with multiple years. The years in effect
128// go from starting_year_ to ending_year_, inclusive. starting_year_ <=
129// ending_year_. save_ is in effect for times from the specified time
130// onward, including the specified time. When the specified time is
131// local, it uses the save_ from the chronologically previous Rule, or if
132// there is none, 0.
133
134//forward declare to avoid warnings in gcc 6.2
135class Rule;
136bool operator==(const Rule& x, const Rule& y);
137bool operator<(const Rule& x, const Rule& y);
138bool operator==(const Rule& x, const date::year& y);
139bool operator<(const Rule& x, const date::year& y);
140bool operator==(const date::year& x, const Rule& y);
141bool operator<(const date::year& x, const Rule& y);
142bool operator==(const Rule& x, const std::string& y);
143bool operator<(const Rule& x, const std::string& y);
144bool operator==(const std::string& x, const Rule& y);
145bool operator<(const std::string& x, const Rule& y);
146std::ostream& operator<<(std::ostream& os, const Rule& r);
147
148class Rule
149{
150private:
151 std::string name_;
155 std::chrono::minutes save_{0};
156 std::string abbrev_;
157
158public:
159 Rule() = default;
160 explicit Rule(const std::string& s);
162
163 const std::string& name() const {return name_;}
164 const std::string& abbrev() const {return abbrev_;}
165
166 const MonthDayTime& mdt() const {return starting_at_;}
167 const date::year& starting_year() const {return starting_year_;}
168 const date::year& ending_year() const {return ending_year_;}
169 const std::chrono::minutes& save() const {return save_;}
170
171 static void split_overlaps(std::vector<Rule>& rules);
172
173 friend bool operator==(const Rule& x, const Rule& y);
174 friend bool operator<(const Rule& x, const Rule& y);
175 friend bool operator==(const Rule& x, const date::year& y);
176 friend bool operator<(const Rule& x, const date::year& y);
177 friend bool operator==(const date::year& x, const Rule& y);
178 friend bool operator<(const date::year& x, const Rule& y);
179 friend bool operator==(const Rule& x, const std::string& y);
180 friend bool operator<(const Rule& x, const std::string& y);
181 friend bool operator==(const std::string& x, const Rule& y);
182 friend bool operator<(const std::string& x, const Rule& y);
183
184 friend std::ostream& operator<<(std::ostream& os, const Rule& r);
185
186private:
187 date::day day() const;
188 date::month month() const;
189 static void split_overlaps(std::vector<Rule>& rules, std::size_t i, std::size_t& e);
190 static bool overlaps(const Rule& x, const Rule& y);
191 static void split(std::vector<Rule>& rules, std::size_t i, std::size_t k,
192 std::size_t& e);
193};
194
195inline bool operator!=(const Rule& x, const Rule& y) {return !(x == y);}
196inline bool operator> (const Rule& x, const Rule& y) {return y < x;}
197inline bool operator<=(const Rule& x, const Rule& y) {return !(y < x);}
198inline bool operator>=(const Rule& x, const Rule& y) {return !(x < y);}
199
200inline bool operator!=(const Rule& x, const date::year& y) {return !(x == y);}
201inline bool operator> (const Rule& x, const date::year& y) {return y < x;}
202inline bool operator<=(const Rule& x, const date::year& y) {return !(y < x);}
203inline bool operator>=(const Rule& x, const date::year& y) {return !(x < y);}
204
205inline bool operator!=(const date::year& x, const Rule& y) {return !(x == y);}
206inline bool operator> (const date::year& x, const Rule& y) {return y < x;}
207inline bool operator<=(const date::year& x, const Rule& y) {return !(y < x);}
208inline bool operator>=(const date::year& x, const Rule& y) {return !(x < y);}
209
210inline bool operator!=(const Rule& x, const std::string& y) {return !(x == y);}
211inline bool operator> (const Rule& x, const std::string& y) {return y < x;}
212inline bool operator<=(const Rule& x, const std::string& y) {return !(y < x);}
213inline bool operator>=(const Rule& x, const std::string& y) {return !(x < y);}
214
215inline bool operator!=(const std::string& x, const Rule& y) {return !(x == y);}
216inline bool operator> (const std::string& x, const Rule& y) {return y < x;}
217inline bool operator<=(const std::string& x, const Rule& y) {return !(y < x);}
218inline bool operator>=(const std::string& x, const Rule& y) {return !(x < y);}
219
221{
223
224 std::chrono::seconds gmtoff_;
226
227#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
228 union U
229#else
230 struct U
231#endif
232 {
233 std::string rule_;
234 std::chrono::minutes save_;
235
236 ~U() {}
237 U() {}
238 U(const U&) {}
239 U& operator=(const U&) = delete;
240 } u;
241
242 std::string format_;
248 std::chrono::minutes initial_save_{0};
249 std::string initial_abbrev_;
250 std::pair<const Rule*, date::year> first_rule_{nullptr, date::year::min()};
251 std::pair<const Rule*, date::year> last_rule_{nullptr, date::year::max()};
252
253 ~zonelet();
254 zonelet();
255 zonelet(const zonelet& i);
256 zonelet& operator=(const zonelet&) = delete;
257};
258
259#else // USE_OS_TZDB
260
261struct ttinfo
262{
263 std::int32_t tt_gmtoff;
264 unsigned char tt_isdst;
265 unsigned char tt_abbrind;
266 unsigned char pad[2];
267};
268
269static_assert(sizeof(ttinfo) == 8, "");
270
271struct expanded_ttinfo
272{
273 std::chrono::seconds offset;
274 std::string abbrev;
275 bool is_dst;
276};
277
278struct transition
279{
280 sys_seconds timepoint;
281 const expanded_ttinfo* info;
282
283 transition(sys_seconds tp, const expanded_ttinfo* i = nullptr)
284 : timepoint(tp)
285 , info(i)
286 {}
287
288 friend
289 std::ostream&
290 operator<<(std::ostream& os, const transition& t)
291 {
292 using date::operator<<;
293 os << t.timepoint << "Z ";
294 if (t.info->offset >= std::chrono::seconds{0})
295 os << '+';
296 os << make_time(t.info->offset);
297 if (t.info->is_dst > 0)
298 os << " daylight ";
299 else
300 os << " standard ";
301 os << t.info->abbrev;
302 return os;
303 }
304};
305
306#endif // USE_OS_TZDB
307
308} // namespace detail
309
310} // namespace date
311
312#if defined(_MSC_VER) && (_MSC_VER < 1900)
313#include "tz.h"
314#endif
315
316#endif // TZ_PRIVATE_H
friend std::istream & operator>>(std::istream &is, MonthDayTime &x)
std::chrono::seconds s_
Definition: tz_private.h:100
void canonicalize(date::year y)
Definition: tz.cpp:925
std::chrono::hours h_
Definition: tz_private.h:98
std::chrono::minutes m_
Definition: tz_private.h:99
union date::detail::MonthDayTime::U u
int compare(date::year y, const MonthDayTime &x, date::year yx, std::chrono::seconds offset, std::chrono::minutes prev_save) const
Definition: tz.cpp:814
sys_seconds to_sys(date::year y, std::chrono::seconds offset, std::chrono::seconds save) const
Definition: tz.cpp:856
sys_days to_sys_days(date::year y) const
Definition: tz.cpp:891
date::month month() const
Definition: tz.cpp:798
sys_seconds to_time_point(date::year y) const
Definition: tz.cpp:918
friend std::ostream & operator<<(std::ostream &os, const MonthDayTime &x)
date::day day() const
Definition: tz.cpp:782
std::string name_
Definition: tz_private.h:151
static void split_overlaps(std::vector< Rule > &rules)
Definition: tz.cpp:1397
MonthDayTime starting_at_
Definition: tz_private.h:154
const std::string & abbrev() const
Definition: tz_private.h:164
friend bool operator<(const std::string &x, const Rule &y)
friend std::ostream & operator<<(std::ostream &os, const Rule &r)
friend bool operator==(const Rule &x, const date::year &y)
date::year ending_year_
Definition: tz_private.h:153
friend bool operator<(const Rule &x, const Rule &y)
const std::chrono::minutes & save() const
Definition: tz_private.h:169
const std::string & name() const
Definition: tz_private.h:163
const date::year & starting_year() const
Definition: tz_private.h:167
date::year starting_year_
Definition: tz_private.h:152
friend bool operator==(const Rule &x, const std::string &y)
date::day day() const
Definition: tz.cpp:1264
friend bool operator==(const date::year &x, const Rule &y)
const date::year & ending_year() const
Definition: tz_private.h:168
friend bool operator==(const Rule &x, const Rule &y)
friend bool operator<(const date::year &x, const Rule &y)
friend bool operator<(const Rule &x, const std::string &y)
static bool overlaps(const Rule &x, const Rule &y)
Definition: tz.cpp:1289
date::month month() const
Definition: tz.cpp:1270
friend bool operator==(const std::string &x, const Rule &y)
std::chrono::minutes save_
Definition: tz_private.h:155
const MonthDayTime & mdt() const
Definition: tz_private.h:166
static void split(std::vector< Rule > &rules, std::size_t i, std::size_t k, std::size_t &e)
Definition: tz.cpp:1304
std::string abbrev_
Definition: tz_private.h:156
friend bool operator<(const Rule &x, const date::year &y)
static CONSTCD11 year max() NOEXCEPT
Definition: date.h:420
static CONSTCD11 year min() NOEXCEPT
Definition: date.h:419
bool operator>(const Rule &x, const Rule &y)
Definition: tz_private.h:196
bool operator==(const Rule &x, const Rule &y)
Definition: tz.cpp:1173
std::ostream & operator<<(std::ostream &os, const MonthDayTime &x)
Definition: tz.cpp:1058
std::istream & operator>>(std::istream &is, MonthDayTime &x)
Definition: tz.cpp:964
bool operator>=(const Rule &x, const Rule &y)
Definition: tz_private.h:198
bool operator<(const Rule &x, const Rule &y)
Definition: tz.cpp:1182
bool operator<=(const Rule &x, const Rule &y)
Definition: tz_private.h:197
bool operator!=(const Rule &x, const Rule &y)
Definition: tz_private.h:195
CONSTDATA date::month jan
Definition: date.h:1991
Definition: date.h:88
local_time< std::chrono::seconds > local_seconds
Definition: date.h:201
CONSTCD11 hh_mm_ss< std::chrono::duration< Rep, Period > > make_time(const std::chrono::duration< Rep, Period > &d)
Definition: date.h:4200
sys_time< std::chrono::seconds > sys_seconds
Definition: date.h:194
sys_time< days > sys_days
Definition: date.h:193
std::chrono::minutes initial_save_
Definition: tz_private.h:248
local_seconds until_std_
Definition: tz_private.h:246
std::pair< const Rule *, date::year > first_rule_
Definition: tz_private.h:250
std::string format_
Definition: tz_private.h:242
union date::detail::zonelet::U u
std::string initial_abbrev_
Definition: tz_private.h:249
std::pair< const Rule *, date::year > last_rule_
Definition: tz_private.h:251
std::chrono::seconds gmtoff_
Definition: tz_private.h:224
date::year until_year_
Definition: tz_private.h:243
zonelet & operator=(const zonelet &)=delete
MonthDayTime until_date_
Definition: tz_private.h:244
sys_seconds until_utc_
Definition: tz_private.h:245
local_seconds until_loc_
Definition: tz_private.h:247
date::month_weekday_last month_weekday_last_
Definition: tz_private.h:80
date::month_day month_day_
Definition: tz_private.h:79
U & operator=(const date::month_day &x)
Definition: tz.cpp:870
U & operator=(const U &)=delete
std::chrono::minutes save_
Definition: tz_private.h:234