File indexing completed on 2025-08-28 08:27:14
0001 #ifndef TZ_PRIVATE_H
0002 #define TZ_PRIVATE_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
0031 #include "tz.h"
0032 #else
0033 #include "date.h"
0034 #include <vector>
0035 #endif
0036
0037 namespace arrow_vendored::date
0038 {
0039
0040 namespace detail
0041 {
0042
0043 #if !USE_OS_TZDB
0044
0045 enum class tz {utc, local, standard};
0046
0047
0048 class MonthDayTime;
0049 std::istream& operator>>(std::istream& is, MonthDayTime& x);
0050 std::ostream& operator<<(std::ostream& os, const MonthDayTime& x);
0051
0052
0053 class MonthDayTime
0054 {
0055 private:
0056 struct pair
0057 {
0058 #if defined(_MSC_VER) && (_MSC_VER < 1900)
0059 pair() : month_day_(date::jan / 1), weekday_(0U) {}
0060
0061 pair(const date::month_day& month_day, const date::weekday& weekday)
0062 : month_day_(month_day), weekday_(weekday) {}
0063 #endif
0064
0065 date::month_day month_day_;
0066 date::weekday weekday_;
0067 };
0068
0069 enum Type {month_day, month_last_dow, lteq, gteq};
0070
0071 Type type_{month_day};
0072
0073 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
0074 union U
0075 #else
0076 struct U
0077 #endif
0078 {
0079 date::month_day month_day_;
0080 date::month_weekday_last month_weekday_last_;
0081 pair month_day_weekday_;
0082
0083 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
0084 U() : month_day_{date::jan/1} {}
0085 #else
0086 U() :
0087 month_day_(date::jan/1),
0088 month_weekday_last_(date::month(0U), date::weekday_last(date::weekday(0U)))
0089 {}
0090
0091 #endif
0092
0093 U& operator=(const date::month_day& x);
0094 U& operator=(const date::month_weekday_last& x);
0095 U& operator=(const pair& x);
0096 } u;
0097
0098 std::chrono::hours h_{0};
0099 std::chrono::minutes m_{0};
0100 std::chrono::seconds s_{0};
0101 tz zone_{tz::local};
0102
0103 public:
0104 MonthDayTime() = default;
0105 MonthDayTime(local_seconds tp, tz timezone);
0106 MonthDayTime(const date::month_day& md, tz timezone);
0107
0108 date::day day() const;
0109 date::month month() const;
0110 tz zone() const {return zone_;}
0111
0112 void canonicalize(date::year y);
0113
0114 sys_seconds
0115 to_sys(date::year y, std::chrono::seconds offset, std::chrono::seconds save) const;
0116 sys_days to_sys_days(date::year y) const;
0117
0118 sys_seconds to_time_point(date::year y) const;
0119 int compare(date::year y, const MonthDayTime& x, date::year yx,
0120 std::chrono::seconds offset, std::chrono::minutes prev_save) const;
0121
0122 friend std::istream& operator>>(std::istream& is, MonthDayTime& x);
0123 friend std::ostream& operator<<(std::ostream& os, const MonthDayTime& x);
0124 };
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135 class Rule;
0136 bool operator==(const Rule& x, const Rule& y);
0137 bool operator<(const Rule& x, const Rule& y);
0138 bool operator==(const Rule& x, const date::year& y);
0139 bool operator<(const Rule& x, const date::year& y);
0140 bool operator==(const date::year& x, const Rule& y);
0141 bool operator<(const date::year& x, const Rule& y);
0142 bool operator==(const Rule& x, const std::string& y);
0143 bool operator<(const Rule& x, const std::string& y);
0144 bool operator==(const std::string& x, const Rule& y);
0145 bool operator<(const std::string& x, const Rule& y);
0146 std::ostream& operator<<(std::ostream& os, const Rule& r);
0147
0148 class Rule
0149 {
0150 private:
0151 std::string name_;
0152 date::year starting_year_{0};
0153 date::year ending_year_{0};
0154 MonthDayTime starting_at_;
0155 std::chrono::minutes save_{0};
0156 std::string abbrev_;
0157
0158 public:
0159 Rule() = default;
0160 explicit Rule(const std::string& s);
0161 Rule(const Rule& r, date::year starting_year, date::year ending_year);
0162
0163 const std::string& name() const {return name_;}
0164 const std::string& abbrev() const {return abbrev_;}
0165
0166 const MonthDayTime& mdt() const {return starting_at_;}
0167 const date::year& starting_year() const {return starting_year_;}
0168 const date::year& ending_year() const {return ending_year_;}
0169 const std::chrono::minutes& save() const {return save_;}
0170
0171 static void split_overlaps(std::vector<Rule>& rules);
0172
0173 friend bool operator==(const Rule& x, const Rule& y);
0174 friend bool operator<(const Rule& x, const Rule& y);
0175 friend bool operator==(const Rule& x, const date::year& y);
0176 friend bool operator<(const Rule& x, const date::year& y);
0177 friend bool operator==(const date::year& x, const Rule& y);
0178 friend bool operator<(const date::year& x, const Rule& y);
0179 friend bool operator==(const Rule& x, const std::string& y);
0180 friend bool operator<(const Rule& x, const std::string& y);
0181 friend bool operator==(const std::string& x, const Rule& y);
0182 friend bool operator<(const std::string& x, const Rule& y);
0183
0184 friend std::ostream& operator<<(std::ostream& os, const Rule& r);
0185
0186 private:
0187 date::day day() const;
0188 date::month month() const;
0189 static void split_overlaps(std::vector<Rule>& rules, std::size_t i, std::size_t& e);
0190 static bool overlaps(const Rule& x, const Rule& y);
0191 static void split(std::vector<Rule>& rules, std::size_t i, std::size_t k,
0192 std::size_t& e);
0193 };
0194
0195 inline bool operator!=(const Rule& x, const Rule& y) {return !(x == y);}
0196 inline bool operator> (const Rule& x, const Rule& y) {return y < x;}
0197 inline bool operator<=(const Rule& x, const Rule& y) {return !(y < x);}
0198 inline bool operator>=(const Rule& x, const Rule& y) {return !(x < y);}
0199
0200 inline bool operator!=(const Rule& x, const date::year& y) {return !(x == y);}
0201 inline bool operator> (const Rule& x, const date::year& y) {return y < x;}
0202 inline bool operator<=(const Rule& x, const date::year& y) {return !(y < x);}
0203 inline bool operator>=(const Rule& x, const date::year& y) {return !(x < y);}
0204
0205 inline bool operator!=(const date::year& x, const Rule& y) {return !(x == y);}
0206 inline bool operator> (const date::year& x, const Rule& y) {return y < x;}
0207 inline bool operator<=(const date::year& x, const Rule& y) {return !(y < x);}
0208 inline bool operator>=(const date::year& x, const Rule& y) {return !(x < y);}
0209
0210 inline bool operator!=(const Rule& x, const std::string& y) {return !(x == y);}
0211 inline bool operator> (const Rule& x, const std::string& y) {return y < x;}
0212 inline bool operator<=(const Rule& x, const std::string& y) {return !(y < x);}
0213 inline bool operator>=(const Rule& x, const std::string& y) {return !(x < y);}
0214
0215 inline bool operator!=(const std::string& x, const Rule& y) {return !(x == y);}
0216 inline bool operator> (const std::string& x, const Rule& y) {return y < x;}
0217 inline bool operator<=(const std::string& x, const Rule& y) {return !(y < x);}
0218 inline bool operator>=(const std::string& x, const Rule& y) {return !(x < y);}
0219
0220 struct zonelet
0221 {
0222 enum tag {has_rule, has_save, is_empty};
0223
0224 std::chrono::seconds gmtoff_;
0225 tag tag_ = has_rule;
0226
0227 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
0228 union U
0229 #else
0230 struct U
0231 #endif
0232 {
0233 std::string rule_;
0234 std::chrono::minutes save_;
0235
0236 ~U() {}
0237 U() {}
0238 U(const U&) {}
0239 U& operator=(const U&) = delete;
0240 } u;
0241
0242 std::string format_;
0243 date::year until_year_{0};
0244 MonthDayTime until_date_;
0245 sys_seconds until_utc_;
0246 local_seconds until_std_;
0247 local_seconds until_loc_;
0248 std::chrono::minutes initial_save_{0};
0249 std::string initial_abbrev_;
0250 std::pair<const Rule*, date::year> first_rule_{nullptr, date::year::min()};
0251 std::pair<const Rule*, date::year> last_rule_{nullptr, date::year::max()};
0252
0253 ~zonelet();
0254 zonelet();
0255 zonelet(const zonelet& i);
0256 zonelet& operator=(const zonelet&) = delete;
0257 };
0258
0259 #else
0260
0261 struct ttinfo
0262 {
0263 std::int32_t tt_gmtoff;
0264 unsigned char tt_isdst;
0265 unsigned char tt_abbrind;
0266 unsigned char pad[2];
0267 };
0268
0269 static_assert(sizeof(ttinfo) == 8, "");
0270
0271 struct expanded_ttinfo
0272 {
0273 std::chrono::seconds offset;
0274 std::string abbrev;
0275 bool is_dst;
0276 };
0277
0278 struct transition
0279 {
0280 sys_seconds timepoint;
0281 const expanded_ttinfo* info;
0282
0283 transition(sys_seconds tp, const expanded_ttinfo* i = nullptr)
0284 : timepoint(tp)
0285 , info(i)
0286 {}
0287
0288 friend
0289 std::ostream&
0290 operator<<(std::ostream& os, const transition& t)
0291 {
0292 date::operator<<(os, t.timepoint) << "Z ";
0293 if (t.info->offset >= std::chrono::seconds{0})
0294 os << '+';
0295 os << make_time(t.info->offset);
0296 if (t.info->is_dst > 0)
0297 os << " daylight ";
0298 else
0299 os << " standard ";
0300 os << t.info->abbrev;
0301 return os;
0302 }
0303 };
0304
0305 #endif
0306
0307 }
0308
0309 }
0310
0311 #if defined(_MSC_VER) && (_MSC_VER < 1900)
0312 #include "tz.h"
0313 #endif
0314
0315 #endif