From 9343e31599249b591eab0dac84b91ff5d9f4814b Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sun, 24 May 2020 21:16:16 -0400 Subject: [PATCH] Give Posix::time_zone equality comparison --- include/date/ptz.h | 49 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/include/date/ptz.h b/include/date/ptz.h index ad4c379..808789d 100644 --- a/include/date/ptz.h +++ b/include/date/ptz.h @@ -91,8 +91,34 @@ public: friend std::ostream& operator<<(std::ostream& os, const rule& r); friend unsigned read_date(const string_t& s, unsigned i, rule& r); + friend bool operator==(const rule& x, const rule& y); }; +inline +bool +operator==(const rule& x, const rule& y) +{ + if (x.mode_ != y.mode_) + return false; + switch (x.mode_) + { + case rule::J: + case rule::N: + return x.n_ == y.n_; + case rule::M: + return x.m_ == y.m_ && x.n_ == y.n_ && x.wd_ == y.wd_; + default: + return true; + } +} + +inline +bool +operator!=(const rule& x, const rule& y) +{ + return !(x == y); +} + inline date::local_seconds rule::operator()(date::year y) const @@ -130,7 +156,7 @@ rule::to_string() const std::string nm; if (off != hours{2}) { - date::hh_mm_ss offset{off}; + date::hh_mm_ss offset{off}; nm = '/'; nm += std::to_string(offset.hours().count()); if (offset.minutes() != minutes{0} || offset.seconds() != seconds{0}) @@ -237,6 +263,8 @@ public: const time_zone* operator->() const {return this;} std::string name() const; + + friend bool operator==(const time_zone& x, const time_zone& y); }; inline @@ -525,6 +553,25 @@ time_zone::name() const return nm; } +inline +bool +operator==(const time_zone& x, const time_zone& y) +{ + return x.std_abbrev_ == y.std_abbrev_ && + x.dst_abbrev_ == y. dst_abbrev_ && + x.offset_ == y.offset_ && + x.save_ == y.save_ && + x.start_rule_ == y.start_rule_ && + x.end_rule_ == y.end_rule_; +} + +inline +bool +operator!=(const time_zone& x, const time_zone& y) +{ + return !(x == y); +} + namespace detail {