diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 6dfb15f6..4a3aa2d3 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -171,9 +171,9 @@ namespace etl //*********************************************************************** /// Compare day with another. - /// if day < other, returns -1; - /// else if day > other, returns 1; - /// else returns 0; + /// if day < other, returns -1 + /// else if day > other, returns 1 + /// else returns 0 //*********************************************************************** ETL_NODISCARD ETL_CONSTEXPR14 int compare(const day& other) const ETL_NOEXCEPT @@ -336,9 +336,9 @@ namespace etl #if ETL_HAS_CHRONO_LITERALS_DAY namespace etl { - namespace literals + inline namespace literals { - namespace chrono_literals + inline namespace chrono_literals { #if ETL_USING_VERBOSE_CHRONO_LITERALS inline ETL_CONSTEXPR14 etl::chrono::day operator ""_day(unsigned long long d) noexcept diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index b16ed6ba..a1cd5b71 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -106,8 +106,8 @@ namespace etl { public: - typedef TRep rep; - typedef typename TPeriod::type period; + using rep = TRep; + using period = typename TPeriod::type; //*********************************************************************** ETL_CONSTEXPR duration() ETL_NOEXCEPT @@ -285,9 +285,9 @@ namespace etl //*********************************************************************** /// Compare duration with another. - /// if duration < other, returns -1; - /// else if duration > other, returns 1; - /// else returns 0; + /// if duration < other, returns -1 + /// else if duration > other, returns 1 + /// else returns 0 //*********************************************************************** template ETL_CONSTEXPR14 int compare(const duration& other) const ETL_NOEXCEPT @@ -313,22 +313,22 @@ namespace etl /// Duration types //*********************************************************************** #if (ETL_USING_64BIT_TYPES) - typedef etl::chrono::duration nanoseconds; - typedef etl::chrono::duration microseconds; - typedef etl::chrono::duration milliseconds; - typedef etl::chrono::duration > seconds; + using nanoseconds = etl::chrono::duration; + using microseconds = etl::chrono::duration; + using milliseconds = etl::chrono::duration; + using seconds = etl::chrono::duration>; #else - typedef etl::chrono::duration nanoseconds; - typedef etl::chrono::duration microseconds; - typedef etl::chrono::duration milliseconds; - typedef etl::chrono::duration > seconds; + using nanoseconds = etl::chrono::duration; + using microseconds = etl::chrono::duration; + using milliseconds = etl::chrono::duration; + using seconds = etl::chrono::duration>; #endif - typedef etl::chrono::duration > minutes; - typedef etl::chrono::duration > hours; - typedef etl::chrono::duration > days; - typedef etl::chrono::duration > weeks; - typedef etl::chrono::duration > months; - typedef etl::chrono::duration > years; + using minutes = etl::chrono::duration>; + using hours = etl::chrono::duration>; + using days = etl::chrono::duration>; + using weeks = etl::chrono::duration>; + using months = etl::chrono::duration>; + using years = etl::chrono::duration>; //*********************************************************************** /// duration_cast @@ -336,14 +336,14 @@ namespace etl template ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT { - typedef TRep from_rep; - typedef TPeriod from_period; + using from_rep = TRep ; + using from_period = TPeriod ; - typedef typename TToDuration::rep to_rep; - typedef typename TToDuration::period to_period; + using to_rep = typename TToDuration::rep; + using to_period = typename TToDuration::period; - typedef typename etl::ratio_divide ratio_divide_t; - typedef typename etl::common_type::type common_t; + using ratio_divide_t = typename etl::ratio_divide; + using common_t = typename etl::common_type::type; common_t ct_count = static_cast(d.count()); common_t ct_num = static_cast(ratio_divide_t::type::num); @@ -396,13 +396,13 @@ namespace etl /// Find the common type of two duration types. //*********************************************************************** template - struct common_type, etl::chrono::duration > + struct common_type, etl::chrono::duration> { private: - typedef typename etl::common_type::type value_type; - typedef etl::ratio::value, - etl::chrono::private_chrono::lcm::value> period_type; + using value_type = typename etl::common_type::type ; + using period_type = etl::ratio::value, + etl::chrono::private_chrono::lcm::value>; public: @@ -416,7 +416,7 @@ namespace etl ETL_CONSTEXPR14 bool operator ==(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) ETL_NOEXCEPT { - typedef typename etl::common_type, etl::chrono::duration >::type common_t; + using common_t = typename etl::common_type, etl::chrono::duration >::type; common_t l = etl::chrono::duration_cast(lhs); common_t r = etl::chrono::duration_cast(rhs); @@ -441,7 +441,7 @@ namespace etl ETL_CONSTEXPR14 bool operator <(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) ETL_NOEXCEPT { - typedef typename etl::common_type, etl::chrono::duration >::type common_t; + using common_t = typename etl::common_type, etl::chrono::duration >::type; common_t l = etl::chrono::duration_cast(lhs); common_t r = etl::chrono::duration_cast(rhs); @@ -487,7 +487,7 @@ namespace etl [[nodiscard]] constexpr auto operator <=>(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) ETL_NOEXCEPT { - typedef typename etl::common_type, etl::chrono::duration >::type common_t; + using common_t = typename etl::common_type, etl::chrono::duration >::type; common_t l = etl::chrono::duration_cast(lhs); common_t r = etl::chrono::duration_cast(rhs); @@ -709,9 +709,9 @@ namespace etl #if ETL_HAS_CHRONO_LITERALS_DURATION namespace etl { - namespace literals + inline namespace literals { - namespace chrono_literals + inline namespace chrono_literals { //*********************************************************************** /// Literal for hours duration diff --git a/include/etl/private/chrono/hh_mm_ss.h b/include/etl/private/chrono/hh_mm_ss.h index d044c726..4c92d2ee 100644 --- a/include/etl/private/chrono/hh_mm_ss.h +++ b/include/etl/private/chrono/hh_mm_ss.h @@ -44,7 +44,6 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - //typename etl::enable_if::value, TDuration>::type typename etl::enable_if::value, TDuration>::type absolute(TDuration dur) ETL_NOEXCEPT { diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index abd98de9..890893bf 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -165,9 +165,9 @@ namespace etl //*********************************************************************** /// Compare month with another. - /// if month < other, returns -1; - /// else if month > other, returns 1; - /// else returns 0; + /// if month < other, returns -1 + /// else if month > other, returns 1 + /// else returns 0 //*********************************************************************** ETL_NODISCARD ETL_CONSTEXPR14 int compare(const month& other) const ETL_NOEXCEPT @@ -367,68 +367,6 @@ namespace etl static ETL_CONSTANT etl::chrono::month November{ 11 }; static ETL_CONSTANT etl::chrono::month December{ 12 }; #endif - - //************************************************************************* - /// month_day_last - //************************************************************************* - class month_day_last - { - public: - - //************************************************************************* - /// Construct from month. - //************************************************************************* - ETL_CONSTEXPR14 explicit month_day_last(const etl::chrono::month& m_) ETL_NOEXCEPT - : m(m_) - { - } - - //************************************************************************* - /// Get the month. - //************************************************************************* - ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT - { - return m; - } - - //************************************************************************* - /// Is the contained month OK? - //************************************************************************* - bool ok() const ETL_NOEXCEPT - { - return m.ok(); - } - - private: - - etl::chrono::month m; - }; - - //*********************************************************************** - /// Equality operator - //*********************************************************************** - inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_day_last& mdl1, const etl::chrono::month_day_last& mdl2) ETL_NOEXCEPT - { - return (static_cast(mdl1.month()) == static_cast(mdl2.month())); - } - - //*********************************************************************** - /// Inequality operator - //*********************************************************************** - inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_day_last& mdl1, const etl::chrono::month_day_last& mdl2) ETL_NOEXCEPT - { - return !(mdl1 == mdl2); - } - - //*********************************************************************** - /// Spaceship operator - //*********************************************************************** -#if ETL_USING_CPP20 - [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::month_day_last& mdl1, const etl::chrono::month_day_last& mdl2) noexcept - { - return (static_cast(mdl1.month()) <=> static_cast(mdl2.month())); - } -#endif } //************************************************************************* @@ -448,20 +386,5 @@ namespace etl }; #endif - //************************************************************************* - /// Hash function for etl::chrono::month_day_last - //************************************************************************* -#if ETL_USING_8BIT_TYPES - template <> - struct hash - { - size_t operator()(const etl::chrono::month_day_last& mdl) const - { - etl::chrono::month::rep value = static_cast(static_cast(mdl.month())); - const uint8_t* p = reinterpret_cast(&value); - return etl::private_hash::generic_hash(p, p + sizeof(value)); - } - }; -#endif } diff --git a/include/etl/private/chrono/month_day.h b/include/etl/private/chrono/month_day.h index fbbb4408..f012d797 100644 --- a/include/etl/private/chrono/month_day.h +++ b/include/etl/private/chrono/month_day.h @@ -94,102 +94,13 @@ namespace etl (static_cast(d) <= max_day); } - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_day& lhs, - const etl::chrono::month_day& rhs) ETL_NOEXCEPT - { - return (lhs.d == rhs.d) && (lhs.m == rhs.m); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_day& lhs, - const etl::chrono::month_day& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - - //************************************************************************* - /// Less-than operator. - //************************************************************************* - ETL_NODISCARD friend ETL_CONSTEXPR14 - bool operator <(const etl::chrono::month_day& lhs, - const etl::chrono::month_day& rhs) ETL_NOEXCEPT - { - if (lhs.month() < rhs.month()) - { - return true; - } - else if (lhs.month() == rhs.month()) - { - return lhs.day() < rhs.day(); - } - else - { - return false; - } - } - - //************************************************************************* - /// Less-than-equal operator. - //************************************************************************* - ETL_NODISCARD friend ETL_CONSTEXPR14 - bool operator <=(const etl::chrono::month_day& lhs, - const etl::chrono::month_day& rhs) ETL_NOEXCEPT - { - return !(rhs < lhs); - } - - //************************************************************************* - /// Greater-than operator. - //************************************************************************* - ETL_NODISCARD friend ETL_CONSTEXPR14 - bool operator >(const etl::chrono::month_day& lhs, - const etl::chrono::month_day& rhs) ETL_NOEXCEPT - { - return rhs < lhs; - } - - //************************************************************************* - /// Greater-than-equal operator. - //************************************************************************* - ETL_NODISCARD friend ETL_CONSTEXPR14 - bool operator >=(const etl::chrono::month_day& lhs, - const etl::chrono::month_day& rhs) ETL_NOEXCEPT - { - return !(lhs < rhs); - } - - //*********************************************************************** - /// Spaceship operator - //*********************************************************************** -#if ETL_USING_CPP20 - [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::month_day& lhs, - const etl::chrono::month_day& rhs) noexcept - { - auto cmp = lhs.month() <=> rhs.month(); - - if (cmp != 0) - { - return cmp; - } - else - { - return lhs.day() <=> rhs.day(); - } - } -#endif - //*********************************************************************** /// Compare month_day with another. - /// if month < other.month, returns -1; - /// else if month > other.month, returns 1; - /// else if day < other.day, returns -1; - /// else if day > other.day, returns 1; - /// else returns 0; + /// if month < other.month, returns -1 + /// else if month > other.month, returns 1 + /// else if day < other.day, returns -1 + /// else if day > other.day, returns 1 + /// else returns 0 //*********************************************************************** ETL_NODISCARD ETL_CONSTEXPR14 int compare(const month_day& other) const ETL_NOEXCEPT @@ -206,7 +117,215 @@ namespace etl etl::chrono::month m; etl::chrono::day d; - }; + }; + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return (lhs.day() == rhs.day()) && (lhs.month() == rhs.month()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //************************************************************************* + /// Less-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + if (lhs.month() < rhs.month()) + { + return true; + } + else if (lhs.month() == rhs.month()) + { + return lhs.day() < rhs.day(); + } + else + { + return false; + } + } + + //************************************************************************* + /// Less-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <=(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return rhs < lhs; + } + + //************************************************************************* + /// Greater-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >=(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return !(lhs < rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) noexcept + { + auto cmp = lhs.month() <=> rhs.month(); + + if (cmp != 0) + { + return cmp; + } + else + { + return lhs.day() <=> rhs.day(); + } + } +#endif + + //************************************************************************* + /// month_day_last + //************************************************************************* + class month_day_last + { + public: + + //************************************************************************* + /// Construct from month. + //************************************************************************* + ETL_CONSTEXPR14 explicit month_day_last(const etl::chrono::month& m_) ETL_NOEXCEPT + : m(m_) + { + } + + //************************************************************************* + /// Get the month. + //************************************************************************* + ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Is the contained month OK? + //************************************************************************* + bool ok() const ETL_NOEXCEPT + { + return m.ok(); + } + + //*********************************************************************** + /// Compare month_day with another. + /// if month < other.month, returns -1 + /// else if month > other.month, returns 1 + /// else returns 0 + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR14 int compare(const month_day& other) const ETL_NOEXCEPT + { + if (m < other.month()) return -1; + if (m > other.month()) return 1; + + return 0; + } + + private: + + etl::chrono::month m; + }; + + //*********************************************************************** + /// Equality operator + //*********************************************************************** + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_day_last& mdl1, + const etl::chrono::month_day_last& mdl2) ETL_NOEXCEPT + { + return (static_cast(mdl1.month()) == static_cast(mdl2.month())); + } + + //*********************************************************************** + /// Inequality operator + //*********************************************************************** + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_day_last& mdl1, + const etl::chrono::month_day_last& mdl2) ETL_NOEXCEPT + { + return !(mdl1 == mdl2); + } + + //************************************************************************* + /// Less-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <(const etl::chrono::month_day_last& lhs, + const etl::chrono::month_day_last& rhs) ETL_NOEXCEPT + { + return (lhs.month() < rhs.month()); + } + + //************************************************************************* + /// Less-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <=(const etl::chrono::month_day_last& lhs, + const etl::chrono::month_day_last& rhs) ETL_NOEXCEPT + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >(const etl::chrono::month_day_last& lhs, + const etl::chrono::month_day_last& rhs) ETL_NOEXCEPT + { + return rhs < lhs; + } + + //************************************************************************* + /// Greater-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >=(const etl::chrono::month_day_last& lhs, + const etl::chrono::month_day_last& rhs) ETL_NOEXCEPT + { + return !(lhs < rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::month_day_last& mdl1, const etl::chrono::month_day_last& mdl2) noexcept + { + return (static_cast(mdl1.month()) <=> static_cast(mdl2.month())); + } +#endif } //************************************************************************* @@ -230,5 +349,22 @@ namespace etl } }; #endif + + //************************************************************************* + /// Hash function for etl::chrono::month_day_last + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::month_day_last& mdl) const + { + etl::chrono::month::rep value = static_cast(static_cast(mdl.month())); + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(value)); + } + }; +#endif } diff --git a/include/etl/private/chrono/month_weekday.h b/include/etl/private/chrono/month_weekday.h index 444f91a0..9e05692d 100644 --- a/include/etl/private/chrono/month_weekday.h +++ b/include/etl/private/chrono/month_weekday.h @@ -77,30 +77,31 @@ namespace etl return m.ok() && wdi.ok(); } - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_weekday& lhs, - const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT - { - return (lhs.m == rhs.m) && (lhs.wdi == rhs.wdi); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_weekday& lhs, - const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - private: etl::chrono::month m; etl::chrono::weekday_indexed wdi; }; + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_weekday& lhs, + const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT + { + return (lhs.month() == rhs.month()) && + (lhs.weekday_indexed() == rhs.weekday_indexed()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_weekday& lhs, + const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + //************************************************************************* /// Construct from month and weekday_last. //************************************************************************* @@ -145,29 +146,29 @@ namespace etl return m.ok() && wdl.ok(); } - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_weekday_last& lhs, - const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT - { - return (lhs.m == rhs.m) && (lhs.wdl == rhs.wdl); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_weekday_last& lhs, - const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - private: etl::chrono::month m; etl::chrono::weekday_last wdl; }; + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_weekday_last& lhs, + const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT + { + return (lhs.month() == rhs.month()) && (lhs.weekday_last() == rhs.weekday_last()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_weekday_last& lhs, + const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } } //************************************************************************* diff --git a/include/etl/private/chrono/time_point.h b/include/etl/private/chrono/time_point.h index 142ae385..6faad033 100644 --- a/include/etl/private/chrono/time_point.h +++ b/include/etl/private/chrono/time_point.h @@ -78,7 +78,7 @@ namespace etl /// Copy construct from another time_point with a different duration type. //*************************************************************************** template - explicit time_point(const time_point& rhs) ETL_NOEXCEPT + ETL_CONSTEXPR14 explicit time_point(const time_point& rhs) ETL_NOEXCEPT : dur(rhs.time_since_epoch()) { } @@ -86,7 +86,7 @@ namespace etl //*************************************************************************** /// Assignment operator. //*************************************************************************** - time_point& operator =(const time_point& rhs) ETL_NOEXCEPT + ETL_CONSTEXPR14 time_point& operator =(const time_point& rhs) ETL_NOEXCEPT { dur = rhs.dur; @@ -105,7 +105,7 @@ namespace etl //*************************************************************************** /// Adds a duration. //*************************************************************************** - time_point& operator +=(const duration& rhs) ETL_NOEXCEPT + ETL_CONSTEXPR14 time_point& operator +=(const duration& rhs) ETL_NOEXCEPT { dur += rhs; @@ -115,7 +115,7 @@ namespace etl //*************************************************************************** /// Subtracts a duration. //*************************************************************************** - time_point& operator -=(const duration& rhs) ETL_NOEXCEPT + ETL_CONSTEXPR14 time_point& operator -=(const duration& rhs) ETL_NOEXCEPT { dur -= rhs; @@ -140,6 +140,21 @@ namespace etl return time_point(duration::max()); } + //*********************************************************************** + /// Compare day with another. + /// if time_point < other, returns -1 + /// else if time_point > other, returns 1 + /// else returns 0 + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR14 int compare(const time_point& other) const ETL_NOEXCEPT + { + if (dur < other.dur) return -1; + if (dur > other.dur) return 1; + + return 0; + } + private: duration dur; diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index 7785b206..afef9cce 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -187,6 +187,21 @@ namespace etl return static_cast(value); } + //*********************************************************************** + /// Compare year with another. + /// if year < other, returns -1 + /// else if year > other, returns 1 + /// else returns 0 + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR14 int compare(const year& other) const ETL_NOEXCEPT + { + if (value < other.value) return -1; + if (value > other.value) return 1; + + return 0; + } + private: rep value; @@ -334,9 +349,9 @@ namespace etl #if ETL_HAS_CHRONO_LITERALS_YEAR namespace etl { - namespace literals + inline namespace literals { - namespace chrono_literals + inline namespace chrono_literals { //*********************************************************************** /// Literal for years diff --git a/include/etl/private/chrono/year_month.h b/include/etl/private/chrono/year_month.h index 90386396..672aadd6 100644 --- a/include/etl/private/chrono/year_month.h +++ b/include/etl/private/chrono/year_month.h @@ -86,115 +86,15 @@ namespace etl return y.ok() && m.ok(); } - //************************************************************************* - /// Adds etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::year_month& ym, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month(ym.year() + dy, ym.month()); - } - - //************************************************************************* - /// Adds etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::years& dy, - const etl::chrono::year_month& ym) ETL_NOEXCEPT - { - return etl::chrono::year_month(ym.year() + dy, ym.month()); - } - - //************************************************************************* - /// Adds etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::year_month& ym, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month(ym.year(), ym.month() + dm); - } - - //************************************************************************* - /// Adds etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::months& dm, - const etl::chrono::year_month& ym) ETL_NOEXCEPT - { - return etl::chrono::year_month(ym.year(), ym.month() + dm); - } - - //************************************************************************* - /// Subtracts etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month operator -(const etl::chrono::year_month& ym, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month(ym.year() - dy, ym.month()); - } - - //************************************************************************* - /// Subtracts etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month operator -(const etl::chrono::year_month& ym, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month(ym.year(), ym.month() - dm); - } - - //************************************************************************* - /// Subtracts etl::chrono::year_month - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::year_month& ym1, - const etl::chrono::year_month& ym2) ETL_NOEXCEPT - { - return etl::chrono::months(static_cast(((int(ym1.year()) - int(ym2.year())) * 12) + (unsigned(ym1.month()) - unsigned(ym2.month())))); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month& lhs, - const etl::chrono::year_month& rhs) ETL_NOEXCEPT - { - return (lhs.y == rhs.y) && (lhs.m == rhs.m); - } - - //************************************************************************* - /// Inequality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month& lhs, - const etl::chrono::year_month& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - - //*********************************************************************** - /// Spaceship operator - //*********************************************************************** -#if ETL_USING_CPP20 - [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month& lhs, - const etl::chrono::year_month& rhs) ETL_NOEXCEPT - { - auto cmp = lhs.year()<=> rhs.year(); - - if (cmp != 0) - { - return cmp; - } - else - { - return lhs.month() <=> rhs.month(); - } - } -#endif - //*********************************************************************** /// Compare year_month with another. - /// if month < other.month, returns -1; - /// else if month > other.month, returns 1; - /// else if day < other.day, returns -1; - /// else if day > other.day, returns 1; - /// else returns 0; + /// if month < other.month, returns -1 + /// else if month > other.month, returns 1 + /// else if day < other.day, returns -1 + /// else if day > other.day, returns 1 + /// else returns 0 //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month& other) const ETL_NOEXCEPT { if (y < other.y) return -1; @@ -209,7 +109,159 @@ namespace etl etl::chrono::year y; etl::chrono::month m; - }; + }; + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::year_month& ym, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year() + dy, ym.month()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::years& dy, + const etl::chrono::year_month& ym) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year() + dy, ym.month()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::year_month& ym, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year(), ym.month() + dm); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::months& dm, + const etl::chrono::year_month& ym) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year(), ym.month() + dm); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month operator -(const etl::chrono::year_month& ym, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year() - dy, ym.month()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month operator -(const etl::chrono::year_month& ym, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year(), ym.month() - dm); + } + + //************************************************************************* + /// Subtracts etl::chrono::year_month + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::year_month& ym1, + const etl::chrono::year_month& ym2) ETL_NOEXCEPT + { + return etl::chrono::months(static_cast(((int(ym1.year()) - int(ym2.year())) * 12) + (unsigned(ym1.month()) - unsigned(ym2.month())))); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + return (lhs.year() == rhs.year()) && (lhs.month() == rhs.month()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //************************************************************************* + /// Less-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + if (lhs.year() < rhs.year()) + { + return true; + } + else if (lhs.year() == rhs.year()) + { + return lhs.month() < rhs.month(); + } + else + { + return false; + } + } + + //************************************************************************* + /// Less-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <=(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + return rhs < lhs; + } + + //************************************************************************* + /// Greater-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >=(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + return !(lhs < rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + auto cmp = lhs.year()<=> rhs.year(); + + if (cmp != 0) + { + return cmp; + } + else + { + return lhs.month() <=> rhs.month(); + } + } +#endif } //************************************************************************* diff --git a/include/etl/private/chrono/year_month_day.h b/include/etl/private/chrono/year_month_day.h index ba9993e6..bff1ef5d 100644 --- a/include/etl/private/chrono/year_month_day.h +++ b/include/etl/private/chrono/year_month_day.h @@ -123,7 +123,7 @@ namespace etl } //************************************************************************* - /// Construct from sys_days. + /// Construct from local_days. //************************************************************************* ETL_CONSTEXPR14 year_month_day(const etl::chrono::local_days& ld) ETL_NOEXCEPT { @@ -175,111 +175,54 @@ namespace etl } //************************************************************************* - /// Adds etl::chrono::years + /// //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ymd, - const etl::chrono::years& dy) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::year_month_day& operator +=(const etl::chrono::years& dy) ETL_NOEXCEPT { - return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day()); + y += dy; + + return *this; } //************************************************************************* - /// Adds etl::chrono::years + /// //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::years& dy, - const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::year_month_day& operator +=(const etl::chrono::months& dm) ETL_NOEXCEPT { - return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day()); + m += dm; + + return *this; } //************************************************************************* - /// Adds etl::chrono::months + /// //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ymd, - const etl::chrono::months& dm) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::year_month_day& operator -=(const etl::chrono::years& dy) ETL_NOEXCEPT { - return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day()); + y -= dy; + + return *this; } //************************************************************************* - /// Adds etl::chrono::months + /// //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::months& dm, - const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::year_month_day& operator -=(const etl::chrono::months& dm) ETL_NOEXCEPT { - return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day()); + m -= dm; + + return *this; } - //************************************************************************* - /// Subtracts etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month_day(ymd.year() - dy, ymd.month(), ymd.day()); - } - - //************************************************************************* - /// Subtracts etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month_day(ymd.year(), ymd.month() - dm, ymd.day()); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_day& lhs, - const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT - { - return (lhs.y == rhs.y) && (lhs.m == rhs.m) && (lhs.d == rhs.d); - } - - //************************************************************************* - /// Inequality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_day& lhs, - const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - - //*********************************************************************** - /// Spaceship operator - //*********************************************************************** -#if ETL_USING_CPP20 - [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_day& lhs, - const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT - { - auto cmp = lhs.year() <=> rhs.year(); - - if (cmp != 0) - { - return cmp; - } - - cmp = lhs.month() <=> rhs.month(); - - if (cmp != 0) - { - return cmp; - } - - return lhs.day() <=> rhs.day(); - } -#endif - //*********************************************************************** /// Compare year_month_day with another. - /// if year < other.year, returns -1; - /// else if year > other.year, returns 1; - /// if month < other.month, returns -1; - /// else if month > other.month, returns 1; - /// else if day < other.day, returns -1; - /// else if day > other.day, returns 1; - /// else returns 0; + /// if year < other.year, returns -1 + /// else if year > other.year, returns 1 + /// if month < other.month, returns -1 + /// else if month > other.month, returns 1 + /// else if day < other.day, returns -1 + /// else if day > other.day, returns 1 + /// else returns 0 //*********************************************************************** ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month_day& other) const ETL_NOEXCEPT @@ -362,6 +305,163 @@ namespace etl etl::chrono::day d; }; + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ymd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ymd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day()); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year() - dy, ymd.month(), ymd.day()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year(), ymd.month() - dm, ymd.day()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + return (lhs.year() == rhs.year()) && + (lhs.month() == rhs.month()) && + (lhs.day() == rhs.day()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //************************************************************************* + /// Less-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + if (lhs.year() < rhs.year()) + { + return true; + } + else if (lhs.year() == rhs.year()) + { + if (lhs.month() < rhs.month()) + { + return true; + } + else if (lhs.month() == rhs.month()) + { + return (lhs.day() < rhs.day()); + } + } + else + { + return false; + } + } + + //************************************************************************* + /// Less-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <=(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + return rhs < lhs; + } + + //************************************************************************* + /// Greater-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >=(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + return !(lhs < rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + auto cmp = lhs.year() <=> rhs.year(); + + if (cmp != 0) + { + return cmp; + } + + cmp = lhs.month() <=> rhs.month(); + + if (cmp != 0) + { + return cmp; + } + + return lhs.day() <=> rhs.day(); + } +#endif + //************************************************************************* /// year_month_day_last //************************************************************************* @@ -466,114 +566,13 @@ namespace etl return *this; } - //************************************************************************* - /// Adds etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last()); - } - - //************************************************************************* - /// Adds etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::years& dy, - const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT - { - return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last()); - } - - //************************************************************************* - /// Adds etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm)); - } - - //************************************************************************* - /// Adds etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::months& dm, - const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT - { - return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm)); - } - - //************************************************************************* - /// Subtracts etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month_day_last(ymdl.year() - dy, ymdl.month_day_last()); - } - - //************************************************************************* - /// Subtracts etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() - dm)); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_day_last& lhs, - const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT - { - return (lhs.y == rhs.y) && (lhs.m == rhs.m); - } - - //************************************************************************* - /// Inequality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_day_last& lhs, - const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - - //*********************************************************************** - /// Spaceship operator - //*********************************************************************** -#if ETL_USING_CPP20 - [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_day_last& lhs, - const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT - { - auto cmp1 = lhs.year() <=> rhs.year(); - - if (cmp1 != 0) - { - return cmp1; - } - else - { - auto cmp2 = lhs.month() <=> rhs.month(); - - if (cmp2 != 0) - { - return cmp2; - } - else - { - return lhs.month() <=> rhs.month(); - } - } - } -#endif - //*********************************************************************** /// Compare year_month_day with another. - /// if year < other.year, returns -1; - /// else if year > other.year, returns 1; - /// if month < other.month, returns -1; - /// else if month > other.month, returns 1; - /// else returns 0; + /// if year < other.year, returns -1 + /// else if year > other.year, returns 1 + /// if month < other.month, returns -1 + /// else if month > other.month, returns 1 + /// else returns 0 //*********************************************************************** ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month_day_last& other) const ETL_NOEXCEPT @@ -612,6 +611,60 @@ namespace etl etl::chrono::month m; }; + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm)); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm)); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year() - dy, ymdl.month_day_last()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() - dm)); + } + //************************************************************************* /// Construct from year_month_day_last. //************************************************************************* @@ -621,6 +674,105 @@ namespace etl , d(ymdl.day()) { } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + return (lhs.year() == rhs.year()) && + (lhs.month() == rhs.month()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //************************************************************************* + /// Less-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + if (lhs.year() < rhs.year()) + { + return true; + } + else if (lhs.year() == rhs.year()) + { + return (lhs.month() < rhs.month()); + } + else + { + return false; + } + } + + //************************************************************************* + /// Less-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator <=(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater-than operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + return rhs < lhs; + } + + //************************************************************************* + /// Greater-than-equal operator. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 + inline bool operator >=(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + return !(lhs < rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + auto cmp1 = lhs.year() <=> rhs.year(); + + if (cmp1 != 0) + { + return cmp1; + } + else + { + auto cmp2 = lhs.month() <=> rhs.month(); + + if (cmp2 != 0) + { + return cmp2; + } + else + { + return lhs.month() <=> rhs.month(); + } + } + } +#endif } //************************************************************************* diff --git a/include/etl/private/chrono/year_month_weekday.h b/include/etl/private/chrono/year_month_weekday.h index 58d21fa2..ef8d9b31 100644 --- a/include/etl/private/chrono/year_month_weekday.h +++ b/include/etl/private/chrono/year_month_weekday.h @@ -160,78 +160,6 @@ namespace etl return y.ok() && m.ok() && wdi.ok(); } - //************************************************************************* - /// Adds etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::year_month_weekday& ymwd, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday(ymwd.year() + dy, ymwd.month(), ymwd.weekday_indexed()); - } - - //************************************************************************* - /// Adds etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::years& dy, - const etl::chrono::year_month_weekday& ymwd) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday(ymwd.year() + dy, ymwd.month(), ymwd.weekday_indexed()); - } - - //************************************************************************* - /// Adds etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::year_month_weekday& ymwd, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() + dm, ymwd.weekday_indexed()); - } - - //************************************************************************* - /// Adds etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::months& dm, - const etl::chrono::year_month_weekday& ymwd) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() + dm, ymwd.weekday_indexed()); - } - - //************************************************************************* - /// Subtracts etl::chrono::years - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator -(const etl::chrono::year_month_weekday& ymwd, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday(ymwd.year() - dy, ymwd.month(), ymwd.weekday_indexed()); - } - - //************************************************************************* - /// Subtracts etl::chrono::months - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator -(const etl::chrono::year_month_weekday& ymwd, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() - dm, ymwd.weekday_indexed()); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_weekday& lhs, - const etl::chrono::year_month_weekday& rhs) ETL_NOEXCEPT - { - return (lhs.y == rhs.y) && (lhs.m == rhs.m) && (lhs.wdi == rhs.wdi); - } - - //************************************************************************* - /// Inequality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_weekday& lhs, - const etl::chrono::year_month_weekday& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - //*********************************************************************** /// Converts to etl::chrono::sys_days //*********************************************************************** @@ -280,6 +208,80 @@ namespace etl etl::chrono::weekday_indexed wdi; }; + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year() + dy, ymwd.month(), ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_weekday& ymwd) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year() + dy, ymwd.month(), ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() + dm, ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_weekday& ymwd) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() + dm, ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator -(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year() - dy, ymwd.month(), ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator -(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() - dm, ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_weekday& lhs, + const etl::chrono::year_month_weekday& rhs) ETL_NOEXCEPT + { + return (lhs.year() == rhs.year()) && + (lhs.month() == rhs.month()) && + (lhs.weekday() == rhs.weekday()); + } + + //************************************************************************* + /// Inequality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_weekday& lhs, + const etl::chrono::year_month_weekday& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + //************************************************************************* /// year_month_weekday_last //************************************************************************* @@ -375,126 +377,6 @@ namespace etl return *this; } - //************************************************************************* - /// Adds etl::chrono::years and const etl::chrono::year_month_weekday_last. - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::year_month_weekday_last& ymwdl, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(), ymwdl.weekday_last()); - } - - //************************************************************************* - /// Adds etl::chrono::years and const etl::chrono::year_month_weekday_last. - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::years& dy, - const etl::chrono::year_month_weekday_last& ymwdl) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(), ymwdl.weekday_last()); - } - - //************************************************************************* - /// Adds const etl::chrono::year_month_weekday_last and etl::chrono::months. - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::year_month_weekday_last& ymwdl, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() + dm, ymwdl.weekday_last()); - } - - //************************************************************************* - /// Adds etl::chrono::months and const etl::chrono::year_month_weekday_last. - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::months& dm, - const etl::chrono::year_month_weekday_last& ymwdl) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() + dm, ymwdl.weekday_last()); - } - - //************************************************************************* - /// Subtracts etl::chrono::years from const etl::chrono::year_month_weekday_last. - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator -(const etl::chrono::year_month_weekday_last& ymwdl, - const etl::chrono::years& dy) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday_last(ymwdl.year() - dy, ymwdl.month(), ymwdl.weekday_last()); - } - - //************************************************************************* - /// Subtracts etl::chrono::months from const etl::chrono::year_month_weekday_last - //************************************************************************* - friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator -(const etl::chrono::year_month_weekday_last& ymwdl, - const etl::chrono::months& dm) ETL_NOEXCEPT - { - return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() - dm, ymwdl.weekday_last()); - } - - //************************************************************************* - /// Equality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_weekday_last& lhs, - const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT - { - return (lhs.y == rhs.y) && (lhs.m == rhs.m) && (lhs.weekday() == rhs.weekday()); - } - - //************************************************************************* - /// Inequality operator. - //************************************************************************* - friend ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_weekday_last& lhs, - const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT - { - return !(lhs == rhs); - } - - //*********************************************************************** - /// Spaceship operator - //*********************************************************************** -#if ETL_USING_CPP20 - [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_weekday_last& lhs, - const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT - { - auto cmp1 = lhs.year() <=> rhs.year(); - - if (cmp1 != 0) - { - return cmp1; - } - else - { - auto cmp2 = lhs.month() <=> rhs.month(); - - if (cmp2 != 0) - { - return cmp2; - } - else - { - return lhs.weekday().c_encoding() <=> rhs.weekday().c_encoding(); - } - } - } -#endif - - //*********************************************************************** - /// Compare year_month_weekday with another. - /// if year < other.year, returns -1; - /// else if year > other.year, returns 1; - /// if month < other.month, returns -1; - /// else if month > other.month, returns 1; - /// else returns 0; - //*********************************************************************** - ETL_NODISCARD - ETL_CONSTEXPR14 int compare(const etl::chrono::year_month_weekday_last& other) const ETL_NOEXCEPT - { - if (y < other.y) return -1; - if (y > other.y) return 1; - if (m < other.m) return -1; - if (m > other.m) return 1; - - return 0; - } - //************************************************************************* /// Converts to etl::chrono::sys_days //************************************************************************* @@ -539,6 +421,80 @@ namespace etl etl::chrono::month m; etl::chrono::weekday_last wdl; }; + + //************************************************************************* + /// Adds etl::chrono::years and const etl::chrono::year_month_weekday_last. + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(), ymwdl.weekday_last()); + } + + //************************************************************************* + /// Adds etl::chrono::years and const etl::chrono::year_month_weekday_last. + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_weekday_last& ymwdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(), ymwdl.weekday_last()); + } + + //************************************************************************* + /// Adds const etl::chrono::year_month_weekday_last and etl::chrono::months. + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() + dm, ymwdl.weekday_last()); + } + + //************************************************************************* + /// Adds etl::chrono::months and const etl::chrono::year_month_weekday_last. + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_weekday_last& ymwdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() + dm, ymwdl.weekday_last()); + } + + //************************************************************************* + /// Subtracts etl::chrono::years from const etl::chrono::year_month_weekday_last. + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator -(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year() - dy, ymwdl.month(), ymwdl.weekday_last()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months from const etl::chrono::year_month_weekday_last + //************************************************************************* + inline ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator -(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() - dm, ymwdl.weekday_last()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_weekday_last& lhs, + const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT + { + return (lhs.year() == rhs.year()) && + (lhs.month() == rhs.month()) && + (lhs.weekday() == rhs.weekday()); + } + + //************************************************************************* + /// Inequality operator. + //************************************************************************* + inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_weekday_last& lhs, + const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } } //*************************************************************************