diff --git a/include/date/tz.h b/include/date/tz.h index 7cf5db5..5fc7297 100644 --- a/include/date/tz.h +++ b/include/date/tz.h @@ -990,27 +990,27 @@ inline bool operator>=(const link& x, const link& y) {return !(x < y);} #if !MISSING_LEAP_SECONDS -class leap +class leap_second { private: sys_seconds date_; public: #if USE_OS_TZDB - DATE_API explicit leap(const sys_seconds& s, detail::undocumented); + DATE_API explicit leap_second(const sys_seconds& s, detail::undocumented); #else - DATE_API explicit leap(const std::string& s, detail::undocumented); + DATE_API explicit leap_second(const std::string& s, detail::undocumented); #endif sys_seconds date() const {return date_;} - friend bool operator==(const leap& x, const leap& y) {return x.date_ == y.date_;} - friend bool operator< (const leap& x, const leap& y) {return x.date_ < y.date_;} + friend bool operator==(const leap_second& x, const leap_second& y) {return x.date_ == y.date_;} + friend bool operator< (const leap_second& x, const leap_second& y) {return x.date_ < y.date_;} template friend bool - operator==(const leap& x, const sys_time& y) + operator==(const leap_second& x, const sys_time& y) { return x.date_ == y; } @@ -1018,7 +1018,7 @@ public: template friend bool - operator< (const leap& x, const sys_time& y) + operator< (const leap_second& x, const sys_time& y) { return x.date_ < y; } @@ -1026,23 +1026,23 @@ public: template friend bool - operator< (const sys_time& x, const leap& y) + operator< (const sys_time& x, const leap_second& y) { return x < y.date_; } - friend DATE_API std::ostream& operator<<(std::ostream& os, const leap& x); + friend DATE_API std::ostream& operator<<(std::ostream& os, const leap_second& x); }; -inline bool operator!=(const leap& x, const leap& y) {return !(x == y);} -inline bool operator> (const leap& x, const leap& y) {return y < x;} -inline bool operator<=(const leap& x, const leap& y) {return !(y < x);} -inline bool operator>=(const leap& x, const leap& y) {return !(x < y);} +inline bool operator!=(const leap_second& x, const leap_second& y) {return !(x == y);} +inline bool operator> (const leap_second& x, const leap_second& y) {return y < x;} +inline bool operator<=(const leap_second& x, const leap_second& y) {return !(y < x);} +inline bool operator>=(const leap_second& x, const leap_second& y) {return !(x < y);} template inline bool -operator==(const sys_time& x, const leap& y) +operator==(const sys_time& x, const leap_second& y) { return y == x; } @@ -1050,7 +1050,7 @@ operator==(const sys_time& x, const leap& y) template inline bool -operator!=(const leap& x, const sys_time& y) +operator!=(const leap_second& x, const sys_time& y) { return !(x == y); } @@ -1058,7 +1058,7 @@ operator!=(const leap& x, const sys_time& y) template inline bool -operator!=(const sys_time& x, const leap& y) +operator!=(const sys_time& x, const leap_second& y) { return !(x == y); } @@ -1066,7 +1066,7 @@ operator!=(const sys_time& x, const leap& y) template inline bool -operator> (const leap& x, const sys_time& y) +operator> (const leap_second& x, const sys_time& y) { return y < x; } @@ -1074,7 +1074,7 @@ operator> (const leap& x, const sys_time& y) template inline bool -operator> (const sys_time& x, const leap& y) +operator> (const sys_time& x, const leap_second& y) { return y < x; } @@ -1082,7 +1082,7 @@ operator> (const sys_time& x, const leap& y) template inline bool -operator<=(const leap& x, const sys_time& y) +operator<=(const leap_second& x, const sys_time& y) { return !(y < x); } @@ -1090,7 +1090,7 @@ operator<=(const leap& x, const sys_time& y) template inline bool -operator<=(const sys_time& x, const leap& y) +operator<=(const sys_time& x, const leap_second& y) { return !(y < x); } @@ -1098,7 +1098,7 @@ operator<=(const sys_time& x, const leap& y) template inline bool -operator>=(const leap& x, const sys_time& y) +operator>=(const leap_second& x, const sys_time& y) { return !(x < y); } @@ -1106,11 +1106,13 @@ operator>=(const leap& x, const sys_time& y) template inline bool -operator>=(const sys_time& x, const leap& y) +operator>=(const sys_time& x, const leap_second& y) { return !(x < y); } +using leap = leap_second; + #endif // !MISSING_LEAP_SECONDS #ifdef _WIN32 @@ -1159,7 +1161,7 @@ struct tzdb std::vector links; #endif #if !MISSING_LEAP_SECONDS - std::vector leaps; + std::vector leap_seconds; #endif #if !USE_OS_TZDB std::vector rules; @@ -1178,7 +1180,7 @@ struct tzdb : version(std::move(src.version)) , zones(std::move(src.zones)) , links(std::move(src.links)) - , leaps(std::move(src.leaps)) + , leap_seconds(std::move(src.leap_seconds)) , rules(std::move(src.rules)) , mappings(std::move(src.mappings)) {} @@ -1188,7 +1190,7 @@ struct tzdb version = std::move(src.version); zones = std::move(src.zones); links = std::move(src.links); - leaps = std::move(src.leaps); + leap_seconds = std::move(src.leap_seconds); rules = std::move(src.rules); mappings = std::move(src.mappings); return *this; @@ -1879,7 +1881,7 @@ utc_clock::from_sys(const sys_time& st) { using std::chrono::seconds; using CD = typename std::common_type::type; - auto const& leaps = get_tzdb().leaps; + auto const& leaps = get_tzdb().leap_seconds; auto const lt = std::upper_bound(leaps.begin(), leaps.end(), st); return utc_time{st.time_since_epoch() + seconds{lt-leaps.begin()}}; } @@ -1893,7 +1895,7 @@ is_leap_second(date::utc_time const& ut) { using std::chrono::seconds; using duration = typename std::common_type::type; - auto const& leaps = get_tzdb().leaps; + auto const& leaps = get_tzdb().leap_seconds; auto tp = sys_time{ut.time_since_epoch()}; auto const lt = std::upper_bound(leaps.begin(), leaps.end(), tp); auto ds = seconds{lt-leaps.begin()}; diff --git a/src/tz.cpp b/src/tz.cpp index 528b5d5..91c8a54 100644 --- a/src/tz.cpp +++ b/src/tz.cpp @@ -1924,12 +1924,12 @@ load_abbreviations(std::istream& inf, std::int32_t tzh_charcnt) template static -std::vector +std::vector load_leaps(std::istream& inf, std::int32_t tzh_leapcnt) { // Read tzh_leapcnt pairs using namespace std::chrono; - std::vector leap_seconds; + std::vector leap_seconds; leap_seconds.reserve(static_cast(tzh_leapcnt)); for (std::int32_t i = 0; i < tzh_leapcnt; ++i) { @@ -1947,7 +1947,7 @@ load_leaps(std::istream& inf, std::int32_t tzh_leapcnt) template static -std::vector +std::vector load_leap_data(std::istream& inf, std::int32_t tzh_leapcnt, std::int32_t tzh_timecnt, std::int32_t tzh_typecnt, std::int32_t tzh_charcnt) @@ -1958,7 +1958,7 @@ load_leap_data(std::istream& inf, } static -std::vector +std::vector load_just_leaps(std::istream& inf) { // Read tzh_leapcnt pairs @@ -2004,7 +2004,7 @@ time_zone::load_data(std::istream& inf, auto infos = load_ttinfo(inf, tzh_typecnt); auto abbrev = load_abbreviations(inf, tzh_charcnt); #if !MISSING_LEAP_SECONDS - auto& leap_seconds = get_tzdb_list().front().leaps; + auto& leap_seconds = get_tzdb_list().front().leap_seconds; if (leap_seconds.empty() && tzh_leapcnt > 0) leap_seconds = load_leaps(inf, tzh_leapcnt); #endif @@ -2072,7 +2072,7 @@ time_zone::init_impl() #if !MISSING_LEAP_SECONDS if (tzh_leapcnt > 0) { - auto& leap_seconds = get_tzdb_list().front().leaps; + auto& leap_seconds = get_tzdb_list().front().leap_seconds; auto itr = leap_seconds.begin(); auto l = itr->date(); seconds leap_count{0}; @@ -2207,7 +2207,7 @@ operator<<(std::ostream& os, const time_zone& z) #if !MISSING_LEAP_SECONDS -leap::leap(const sys_seconds& s, detail::undocumented) +leap_second::leap_second(const sys_seconds& s, detail::undocumented) : date_(s) { } @@ -2613,7 +2613,7 @@ operator<<(std::ostream& os, const time_zone& z) #if !MISSING_LEAP_SECONDS std::ostream& -operator<<(std::ostream& os, const leap& x) +operator<<(std::ostream& os, const leap_second& x) { using namespace date; return os << x.date_ << " +"; @@ -2699,7 +2699,7 @@ init_tzdb() if (in) { in.exceptions(std::ios::failbit | std::ios::badbit); - db->leaps = load_just_leaps(in); + db->leap_seconds = load_just_leaps(in); } else { @@ -2709,7 +2709,7 @@ init_tzdb() if (!in) throw std::runtime_error("Unable to extract leap second information"); in.exceptions(std::ios::failbit | std::ios::badbit); - db->leaps = load_just_leaps(in); + db->leap_seconds = load_just_leaps(in); } # endif // !MISSING_LEAP_SECONDS # ifdef __APPLE__ @@ -2742,9 +2742,9 @@ operator<<(std::ostream& os, const link& x) return os << x.name_ << " --> " << x.target_; } -// leap +// leap_second -leap::leap(const std::string& s, detail::undocumented) +leap_second::leap_second(const std::string& s, detail::undocumented) { using namespace date; std::istringstream in(s); @@ -3443,7 +3443,7 @@ init_tzdb() } else if (word == "Leap") { - db->leaps.push_back(leap(line, detail::undocumented{})); + db->leap_seconds.push_back(leap_second(line, detail::undocumented{})); continue_zone = false; } else if (word == "Zone") @@ -3468,8 +3468,8 @@ init_tzdb() db->zones.shrink_to_fit(); std::sort(db->links.begin(), db->links.end()); db->links.shrink_to_fit(); - std::sort(db->leaps.begin(), db->leaps.end()); - db->leaps.shrink_to_fit(); + std::sort(db->leap_seconds.begin(), db->leap_seconds.end()); + db->leap_seconds.shrink_to_fit(); #ifdef _WIN32 std::string mapping_file = get_install() + folder_delimiter + "windowsZones.xml"; @@ -3564,7 +3564,7 @@ operator<<(std::ostream& os, const tzdb& db) os << x << '\n'; #if !MISSING_LEAP_SECONDS os << '\n'; - for (const auto& x : db.leaps) + for (const auto& x : db.leap_seconds) os << x << '\n'; #endif // !MISSING_LEAP_SECONDS return os; @@ -3624,7 +3624,7 @@ operator<<(std::ostream& os, const tzdb& db) "---------------------------------------------------------" "--------------------------------------------------------\n"); os << title; - for (const auto& x : db.leaps) + for (const auto& x : db.leap_seconds) os << x << '\n'; return os; }