Rename leap to leap_second and leaps to leap_seconds

* At the request of LEWG
This commit is contained in:
Howard Hinnant 2019-11-08 19:24:03 +00:00
parent 67e272a54e
commit 224c71a899
2 changed files with 46 additions and 44 deletions

View File

@ -990,27 +990,27 @@ inline bool operator>=(const link& x, const link& y) {return !(x < y);}
#if !MISSING_LEAP_SECONDS #if !MISSING_LEAP_SECONDS
class leap class leap_second
{ {
private: private:
sys_seconds date_; sys_seconds date_;
public: public:
#if USE_OS_TZDB #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 #else
DATE_API explicit leap(const std::string& s, detail::undocumented); DATE_API explicit leap_second(const std::string& s, detail::undocumented);
#endif #endif
sys_seconds date() const {return date_;} 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_second& x, const leap_second& 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_;}
template <class Duration> template <class Duration>
friend friend
bool bool
operator==(const leap& x, const sys_time<Duration>& y) operator==(const leap_second& x, const sys_time<Duration>& y)
{ {
return x.date_ == y; return x.date_ == y;
} }
@ -1018,7 +1018,7 @@ public:
template <class Duration> template <class Duration>
friend friend
bool bool
operator< (const leap& x, const sys_time<Duration>& y) operator< (const leap_second& x, const sys_time<Duration>& y)
{ {
return x.date_ < y; return x.date_ < y;
} }
@ -1026,23 +1026,23 @@ public:
template <class Duration> template <class Duration>
friend friend
bool bool
operator< (const sys_time<Duration>& x, const leap& y) operator< (const sys_time<Duration>& x, const leap_second& y)
{ {
return x < y.date_; 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_second& x, const leap_second& y) {return !(x == y);}
inline bool operator> (const leap& x, const leap& y) {return y < x;} inline bool operator> (const leap_second& x, const leap_second& y) {return y < x;}
inline bool operator<=(const leap& x, const leap& y) {return !(y < x);} inline bool operator<=(const leap_second& x, const leap_second& 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);}
template <class Duration> template <class Duration>
inline inline
bool bool
operator==(const sys_time<Duration>& x, const leap& y) operator==(const sys_time<Duration>& x, const leap_second& y)
{ {
return y == x; return y == x;
} }
@ -1050,7 +1050,7 @@ operator==(const sys_time<Duration>& x, const leap& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator!=(const leap& x, const sys_time<Duration>& y) operator!=(const leap_second& x, const sys_time<Duration>& y)
{ {
return !(x == y); return !(x == y);
} }
@ -1058,7 +1058,7 @@ operator!=(const leap& x, const sys_time<Duration>& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator!=(const sys_time<Duration>& x, const leap& y) operator!=(const sys_time<Duration>& x, const leap_second& y)
{ {
return !(x == y); return !(x == y);
} }
@ -1066,7 +1066,7 @@ operator!=(const sys_time<Duration>& x, const leap& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator> (const leap& x, const sys_time<Duration>& y) operator> (const leap_second& x, const sys_time<Duration>& y)
{ {
return y < x; return y < x;
} }
@ -1074,7 +1074,7 @@ operator> (const leap& x, const sys_time<Duration>& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator> (const sys_time<Duration>& x, const leap& y) operator> (const sys_time<Duration>& x, const leap_second& y)
{ {
return y < x; return y < x;
} }
@ -1082,7 +1082,7 @@ operator> (const sys_time<Duration>& x, const leap& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator<=(const leap& x, const sys_time<Duration>& y) operator<=(const leap_second& x, const sys_time<Duration>& y)
{ {
return !(y < x); return !(y < x);
} }
@ -1090,7 +1090,7 @@ operator<=(const leap& x, const sys_time<Duration>& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator<=(const sys_time<Duration>& x, const leap& y) operator<=(const sys_time<Duration>& x, const leap_second& y)
{ {
return !(y < x); return !(y < x);
} }
@ -1098,7 +1098,7 @@ operator<=(const sys_time<Duration>& x, const leap& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator>=(const leap& x, const sys_time<Duration>& y) operator>=(const leap_second& x, const sys_time<Duration>& y)
{ {
return !(x < y); return !(x < y);
} }
@ -1106,11 +1106,13 @@ operator>=(const leap& x, const sys_time<Duration>& y)
template <class Duration> template <class Duration>
inline inline
bool bool
operator>=(const sys_time<Duration>& x, const leap& y) operator>=(const sys_time<Duration>& x, const leap_second& y)
{ {
return !(x < y); return !(x < y);
} }
using leap = leap_second;
#endif // !MISSING_LEAP_SECONDS #endif // !MISSING_LEAP_SECONDS
#ifdef _WIN32 #ifdef _WIN32
@ -1159,7 +1161,7 @@ struct tzdb
std::vector<link> links; std::vector<link> links;
#endif #endif
#if !MISSING_LEAP_SECONDS #if !MISSING_LEAP_SECONDS
std::vector<leap> leaps; std::vector<leap_second> leap_seconds;
#endif #endif
#if !USE_OS_TZDB #if !USE_OS_TZDB
std::vector<detail::Rule> rules; std::vector<detail::Rule> rules;
@ -1178,7 +1180,7 @@ struct tzdb
: version(std::move(src.version)) : version(std::move(src.version))
, zones(std::move(src.zones)) , zones(std::move(src.zones))
, links(std::move(src.links)) , links(std::move(src.links))
, leaps(std::move(src.leaps)) , leap_seconds(std::move(src.leap_seconds))
, rules(std::move(src.rules)) , rules(std::move(src.rules))
, mappings(std::move(src.mappings)) , mappings(std::move(src.mappings))
{} {}
@ -1188,7 +1190,7 @@ struct tzdb
version = std::move(src.version); version = std::move(src.version);
zones = std::move(src.zones); zones = std::move(src.zones);
links = std::move(src.links); links = std::move(src.links);
leaps = std::move(src.leaps); leap_seconds = std::move(src.leap_seconds);
rules = std::move(src.rules); rules = std::move(src.rules);
mappings = std::move(src.mappings); mappings = std::move(src.mappings);
return *this; return *this;
@ -1879,7 +1881,7 @@ utc_clock::from_sys(const sys_time<Duration>& st)
{ {
using std::chrono::seconds; using std::chrono::seconds;
using CD = typename std::common_type<Duration, seconds>::type; using CD = typename std::common_type<Duration, seconds>::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); auto const lt = std::upper_bound(leaps.begin(), leaps.end(), st);
return utc_time<CD>{st.time_since_epoch() + seconds{lt-leaps.begin()}}; return utc_time<CD>{st.time_since_epoch() + seconds{lt-leaps.begin()}};
} }
@ -1893,7 +1895,7 @@ is_leap_second(date::utc_time<Duration> const& ut)
{ {
using std::chrono::seconds; using std::chrono::seconds;
using duration = typename std::common_type<Duration, seconds>::type; using duration = typename std::common_type<Duration, seconds>::type;
auto const& leaps = get_tzdb().leaps; auto const& leaps = get_tzdb().leap_seconds;
auto tp = sys_time<duration>{ut.time_since_epoch()}; auto tp = sys_time<duration>{ut.time_since_epoch()};
auto const lt = std::upper_bound(leaps.begin(), leaps.end(), tp); auto const lt = std::upper_bound(leaps.begin(), leaps.end(), tp);
auto ds = seconds{lt-leaps.begin()}; auto ds = seconds{lt-leaps.begin()};

View File

@ -1924,12 +1924,12 @@ load_abbreviations(std::istream& inf, std::int32_t tzh_charcnt)
template <class TimeType> template <class TimeType>
static static
std::vector<leap> std::vector<leap_second>
load_leaps(std::istream& inf, std::int32_t tzh_leapcnt) load_leaps(std::istream& inf, std::int32_t tzh_leapcnt)
{ {
// Read tzh_leapcnt pairs // Read tzh_leapcnt pairs
using namespace std::chrono; using namespace std::chrono;
std::vector<leap> leap_seconds; std::vector<leap_second> leap_seconds;
leap_seconds.reserve(static_cast<std::size_t>(tzh_leapcnt)); leap_seconds.reserve(static_cast<std::size_t>(tzh_leapcnt));
for (std::int32_t i = 0; i < tzh_leapcnt; ++i) 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 <class TimeType> template <class TimeType>
static static
std::vector<leap> std::vector<leap_second>
load_leap_data(std::istream& inf, load_leap_data(std::istream& inf,
std::int32_t tzh_leapcnt, std::int32_t tzh_timecnt, std::int32_t tzh_leapcnt, std::int32_t tzh_timecnt,
std::int32_t tzh_typecnt, std::int32_t tzh_charcnt) std::int32_t tzh_typecnt, std::int32_t tzh_charcnt)
@ -1958,7 +1958,7 @@ load_leap_data(std::istream& inf,
} }
static static
std::vector<leap> std::vector<leap_second>
load_just_leaps(std::istream& inf) load_just_leaps(std::istream& inf)
{ {
// Read tzh_leapcnt pairs // Read tzh_leapcnt pairs
@ -2004,7 +2004,7 @@ time_zone::load_data(std::istream& inf,
auto infos = load_ttinfo(inf, tzh_typecnt); auto infos = load_ttinfo(inf, tzh_typecnt);
auto abbrev = load_abbreviations(inf, tzh_charcnt); auto abbrev = load_abbreviations(inf, tzh_charcnt);
#if !MISSING_LEAP_SECONDS #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) if (leap_seconds.empty() && tzh_leapcnt > 0)
leap_seconds = load_leaps<TimeType>(inf, tzh_leapcnt); leap_seconds = load_leaps<TimeType>(inf, tzh_leapcnt);
#endif #endif
@ -2072,7 +2072,7 @@ time_zone::init_impl()
#if !MISSING_LEAP_SECONDS #if !MISSING_LEAP_SECONDS
if (tzh_leapcnt > 0) 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 itr = leap_seconds.begin();
auto l = itr->date(); auto l = itr->date();
seconds leap_count{0}; seconds leap_count{0};
@ -2207,7 +2207,7 @@ operator<<(std::ostream& os, const time_zone& z)
#if !MISSING_LEAP_SECONDS #if !MISSING_LEAP_SECONDS
leap::leap(const sys_seconds& s, detail::undocumented) leap_second::leap_second(const sys_seconds& s, detail::undocumented)
: date_(s) : date_(s)
{ {
} }
@ -2613,7 +2613,7 @@ operator<<(std::ostream& os, const time_zone& z)
#if !MISSING_LEAP_SECONDS #if !MISSING_LEAP_SECONDS
std::ostream& std::ostream&
operator<<(std::ostream& os, const leap& x) operator<<(std::ostream& os, const leap_second& x)
{ {
using namespace date; using namespace date;
return os << x.date_ << " +"; return os << x.date_ << " +";
@ -2699,7 +2699,7 @@ init_tzdb()
if (in) if (in)
{ {
in.exceptions(std::ios::failbit | std::ios::badbit); in.exceptions(std::ios::failbit | std::ios::badbit);
db->leaps = load_just_leaps(in); db->leap_seconds = load_just_leaps(in);
} }
else else
{ {
@ -2709,7 +2709,7 @@ init_tzdb()
if (!in) if (!in)
throw std::runtime_error("Unable to extract leap second information"); throw std::runtime_error("Unable to extract leap second information");
in.exceptions(std::ios::failbit | std::ios::badbit); 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 # endif // !MISSING_LEAP_SECONDS
# ifdef __APPLE__ # ifdef __APPLE__
@ -2742,9 +2742,9 @@ operator<<(std::ostream& os, const link& x)
return os << x.name_ << " --> " << x.target_; 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; using namespace date;
std::istringstream in(s); std::istringstream in(s);
@ -3443,7 +3443,7 @@ init_tzdb()
} }
else if (word == "Leap") 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; continue_zone = false;
} }
else if (word == "Zone") else if (word == "Zone")
@ -3468,8 +3468,8 @@ init_tzdb()
db->zones.shrink_to_fit(); db->zones.shrink_to_fit();
std::sort(db->links.begin(), db->links.end()); std::sort(db->links.begin(), db->links.end());
db->links.shrink_to_fit(); db->links.shrink_to_fit();
std::sort(db->leaps.begin(), db->leaps.end()); std::sort(db->leap_seconds.begin(), db->leap_seconds.end());
db->leaps.shrink_to_fit(); db->leap_seconds.shrink_to_fit();
#ifdef _WIN32 #ifdef _WIN32
std::string mapping_file = get_install() + folder_delimiter + "windowsZones.xml"; std::string mapping_file = get_install() + folder_delimiter + "windowsZones.xml";
@ -3564,7 +3564,7 @@ operator<<(std::ostream& os, const tzdb& db)
os << x << '\n'; os << x << '\n';
#if !MISSING_LEAP_SECONDS #if !MISSING_LEAP_SECONDS
os << '\n'; os << '\n';
for (const auto& x : db.leaps) for (const auto& x : db.leap_seconds)
os << x << '\n'; os << x << '\n';
#endif // !MISSING_LEAP_SECONDS #endif // !MISSING_LEAP_SECONDS
return os; return os;
@ -3624,7 +3624,7 @@ operator<<(std::ostream& os, const tzdb& db)
"---------------------------------------------------------" "---------------------------------------------------------"
"--------------------------------------------------------\n"); "--------------------------------------------------------\n");
os << title; os << title;
for (const auto& x : db.leaps) for (const auto& x : db.leap_seconds)
os << x << '\n'; os << x << '\n';
return os; return os;
} }