From 10147a1868e404931ca1b8417b2430f35e74d41b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 30 Aug 2024 19:59:16 +0100 Subject: [PATCH] Updates to weekday --- include/etl/private/chrono/day.h | 28 +-- include/etl/private/chrono/duration.h | 21 +- include/etl/private/chrono/month.h | 30 +-- include/etl/private/chrono/weekday.h | 87 ++++----- include/etl/private/chrono/year.h | 30 +-- test/test_chrono_weekday.cpp | 263 +++++++++++++------------- test/test_chrono_year.cpp | 18 +- 7 files changed, 238 insertions(+), 239 deletions(-) diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 812ef06c..91557a95 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -55,7 +55,7 @@ namespace etl /// Construct from unsigned //*********************************************************************** ETL_CONSTEXPR explicit day(unsigned value_) ETL_NOEXCEPT - : value(value_) + : value(static_cast(value_)) { } @@ -83,6 +83,8 @@ namespace etl ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration& rhs) { value = etl::chrono::duration_cast(rhs); + + return *this; } //*********************************************************************** @@ -148,7 +150,7 @@ namespace etl //*********************************************************************** /// Returns true if the day is within the valid 1 to 31 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { return (value >= 1U) && (value <= 31U); } @@ -164,7 +166,7 @@ namespace etl //*********************************************************************** /// The minimum day value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::day min() ETL_NOEXCEPT { return etl::chrono::day(1); } @@ -172,7 +174,7 @@ namespace etl //*********************************************************************** /// The maximum day value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::day max() ETL_NOEXCEPT { return etl::chrono::day(31); } @@ -185,7 +187,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) == static_cast(d2)); } @@ -193,7 +195,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return !(d1 == d2); } @@ -209,7 +211,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) <= static_cast(d2)); } @@ -217,7 +219,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) > static_cast(d2)); } @@ -225,7 +227,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) >= static_cast(d2)); } @@ -244,7 +246,7 @@ namespace etl /// Add etl::chrono::days to etl::chrono::day ///\return etl::chrono::day //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT { etl::chrono::day result(d); @@ -257,7 +259,7 @@ namespace etl /// Add etl::chrono::day to etl::chrono::days ///\return etl::chrono::day //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT { etl::chrono::day result(d); @@ -270,7 +272,7 @@ namespace etl /// Subtract etl::chrono::days from etl::chrono::day ///\return etl::chrono::day //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT { etl::chrono::day result(d); @@ -283,7 +285,7 @@ namespace etl /// Subtract etl::chrono::day from etl::chrono::day ///\return etl::chrono::days //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return etl::chrono::days(static_cast(static_cast(d1)) - static_cast(static_cast(d2))); diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 553ba123..b499f0f4 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -76,25 +76,25 @@ namespace etl } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT { return etl::chrono::duration{ 0, TPeriod()}; } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT { return etl::chrono::duration { etl::numeric_limits::min() }; } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT { return etl::chrono::duration{ etl::numeric_limits::max() }; } //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR TValue count() const ETL_NOEXCEPT + ETL_CONSTEXPR TValue count() const ETL_NOEXCEPT { return value; } @@ -131,9 +131,16 @@ namespace etl template ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT { - return TToDuration(); + using to_value_type = typename TToDuration::value_type; + using to_period = typename TToDuration::period; + + // Calculate the conversion factor between the periods + ETL_CONSTEXPR auto conversion_factor = (static_cast(TPeriod::num) / TPeriod::den) * (to_period::den / to_period::num); + + // Convert the value + to_value_type converted_value = static_cast(d.count() * conversion_factor); + + return TToDuration(converted_value); } } } - -#endif diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index 907b5d84..30653a58 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -150,7 +150,7 @@ namespace etl //*********************************************************************** /// Returns true if the month is within the valid 1 to 31 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { return (value >= 1U) && (value <= 12U); } @@ -158,7 +158,7 @@ namespace etl //*********************************************************************** /// The minimum month value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::month min() ETL_NOEXCEPT { return etl::chrono::month(1); } @@ -166,7 +166,7 @@ namespace etl //*********************************************************************** /// The maximum month value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::month max() ETL_NOEXCEPT { return etl::chrono::month(12); } @@ -184,7 +184,7 @@ namespace etl //*********************************************************************** /// Normalise to a in-range month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR void normalise() ETL_NOEXCEPT + ETL_CONSTEXPR void normalise() ETL_NOEXCEPT { value = ((value % 12U) == 0U) ? 12U : value; } @@ -195,7 +195,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) == static_cast(d2)); } @@ -203,7 +203,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return !(d1 == d2); } @@ -211,7 +211,7 @@ namespace etl //*********************************************************************** /// Less-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) < static_cast(d2)); } @@ -219,7 +219,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) <= static_cast(d2)); } @@ -227,7 +227,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) > static_cast(d2)); } @@ -235,7 +235,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) >= static_cast(d2)); } @@ -254,7 +254,7 @@ namespace etl /// Add etl::chrono::months to etl::chrono::month ///\return etl::chrono::month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT { unsigned int value = static_cast(m); @@ -280,7 +280,7 @@ namespace etl /// Add etl::chrono::month to etl::chrono::months ///\return etl::chrono::month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT { return m + ms; } @@ -289,7 +289,7 @@ namespace etl /// Subtract etl::chrono::months from etl::chrono::month ///\return etl::chrono::month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month operator -(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::month operator -(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT { return m + etl::chrono::months(-ms.count()); } @@ -298,7 +298,7 @@ namespace etl /// Subtract etl::chrono::month from etl::chrono::month ///\return etl::chrono::months //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT { if (m1.ok() && m2.ok()) { @@ -374,7 +374,7 @@ namespace etl //*********************************************************************** constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept { - return etl::chrono::month(m); + return etl::chrono::month(static_cast(m)); } } } diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h index aafb8ee0..fc4df27f 100644 --- a/include/etl/private/chrono/weekday.h +++ b/include/etl/private/chrono/weekday.h @@ -64,7 +64,7 @@ namespace etl /// Construct from unsigned //*********************************************************************** ETL_CONSTEXPR explicit weekday(unsigned value_) ETL_NOEXCEPT - : value(value_) + : value(value_ == 7U ? 0U :value_) { } @@ -153,7 +153,7 @@ namespace etl //*********************************************************************** /// Returns true if the weekday is within the valid 1 to 31 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { return (c_encoding() <= 6U); } @@ -161,7 +161,7 @@ namespace etl //*********************************************************************** /// The minimum weekday value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::weekday min() ETL_NOEXCEPT { return etl::chrono::weekday(0); } @@ -169,7 +169,7 @@ namespace etl //*********************************************************************** /// The maximum weekday value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::weekday max() ETL_NOEXCEPT { return etl::chrono::weekday(6); } @@ -177,15 +177,15 @@ namespace etl //*********************************************************************** /// Get the C encoding of the weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR unsigned c_encoding() const ETL_NOEXCEPT + ETL_CONSTEXPR unsigned c_encoding() const ETL_NOEXCEPT { - return (value == 7U) ? 0U : value; + return value; } //*********************************************************************** /// Get the ISO encoding of the weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR unsigned iso_encoding() const ETL_NOEXCEPT + ETL_CONSTEXPR unsigned iso_encoding() const ETL_NOEXCEPT { return (value == 0U) ? 7U : value; } @@ -203,7 +203,7 @@ namespace etl //*********************************************************************** /// Returns true if the day is a weekend. //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 bool is_weekend() ETL_NOEXCEPT + ETL_CONSTEXPR14 bool is_weekend() ETL_NOEXCEPT { return (c_encoding() == 0U) || (c_encoding() == 6U); } @@ -213,7 +213,7 @@ namespace etl //*********************************************************************** /// Normalise to a in-range weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR void normalise() ETL_NOEXCEPT + ETL_CONSTEXPR void normalise() ETL_NOEXCEPT { value %= 7U; } @@ -224,7 +224,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() == wd2.c_encoding()); } @@ -232,7 +232,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return !(wd1 == wd2); } @@ -240,7 +240,7 @@ namespace etl //*********************************************************************** /// Less-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() < wd2.c_encoding()); } @@ -248,7 +248,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() <= wd2.c_encoding()); } @@ -256,7 +256,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() > wd2.c_encoding()); } @@ -264,7 +264,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() >= wd2.c_encoding()); } @@ -283,15 +283,14 @@ namespace etl /// Add etl::chrono::days to etl::chrono::weekday ///\return etl::chrono::weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday operator +(const etl::chrono::weekday& wd, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::weekday operator +(const etl::chrono::weekday& wd, const etl::chrono::days& ds) ETL_NOEXCEPT { - unsigned int value = wd.c_encoding(); - - value = value % 7U; - int delta = ds.count() % 7; + unsigned int value = wd.c_encoding(); + // Adjust to allow a limited +-7 weekday delta + value %= 7U; value += 7U; value += delta; value %= 7U; @@ -303,7 +302,7 @@ namespace etl /// Add etl::chrono::weekday to etl::chrono::days ///\return etl::chrono::weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& wd) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& wd) ETL_NOEXCEPT { return wd + ds; } @@ -312,7 +311,7 @@ namespace etl /// Subtract etl::chrono::days from etl::chrono::weekday ///\return etl::chrono::weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday operator -(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::weekday operator -(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT { return m + etl::chrono::days(-ds.count()); } @@ -321,38 +320,34 @@ namespace etl /// Subtract etl::chrono::weekday from etl::chrono::weekday ///\return etl::chrono::days //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::days operator -(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::days operator -(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { if (wd1.ok() && wd2.ok()) { - etl::chrono::days ds(static_cast(wd1.c_encoding()) - - static_cast(wd2.c_encoding()) % 12); - - if (wd1 == (wd2 + ds)) - { - return ds; - } + int diff = static_cast(wd1.c_encoding()) - static_cast(wd2.c_encoding()); + + return etl::chrono::days((diff + 7) % 7); } - return etl::chrono::days(); + return etl::chrono::days(0); } #if ETL_USING_CPP17 - inline constexpr etl::chrono::weekday Sunday{ 0 }; - inline constexpr etl::chrono::weekday Monday{ 1 }; - inline constexpr etl::chrono::weekday Tuesday{ 2 }; - inline constexpr etl::chrono::weekday Wednesday{ 3 }; - inline constexpr etl::chrono::weekday Thursday{ 4 }; - inline constexpr etl::chrono::weekday Friday{ 5 }; - inline constexpr etl::chrono::weekday Saturday{ 6 }; + inline constexpr etl::chrono::weekday Sunday{ 0U }; + inline constexpr etl::chrono::weekday Monday{ 1U }; + inline constexpr etl::chrono::weekday Tuesday{ 2U }; + inline constexpr etl::chrono::weekday Wednesday{ 3U }; + inline constexpr etl::chrono::weekday Thursday{ 4U }; + inline constexpr etl::chrono::weekday Friday{ 5U }; + inline constexpr etl::chrono::weekday Saturday{ 6U }; #else - static ETL_CONSTANT etl::chrono::weekday Sunday{ 0 }; - static ETL_CONSTANT etl::chrono::weekday Monday{ 1 }; - static ETL_CONSTANT etl::chrono::weekday Tuesday{ 2 }; - static ETL_CONSTANT etl::chrono::weekday Wednesday{ 3 }; - static ETL_CONSTANT etl::chrono::weekday Thursday{ 4 }; - static ETL_CONSTANT etl::chrono::weekday Friday{ 5 }; - static ETL_CONSTANT etl::chrono::weekday Saturday{ 6 }; + static ETL_CONSTANT etl::chrono::weekday Sunday{ 0U }; + static ETL_CONSTANT etl::chrono::weekday Monday{ 1U }; + static ETL_CONSTANT etl::chrono::weekday Tuesday{ 2U }; + static ETL_CONSTANT etl::chrono::weekday Wednesday{ 3U }; + static ETL_CONSTANT etl::chrono::weekday Thursday{ 4U }; + static ETL_CONSTANT etl::chrono::weekday Friday{ 5U }; + static ETL_CONSTANT etl::chrono::weekday Saturday{ 6U }; #endif } @@ -387,7 +382,7 @@ namespace etl //*********************************************************************** constexpr etl::chrono::weekday operator ""_weekday(unsigned long long m) noexcept { - return etl::chrono::weekday(m); + return etl::chrono::weekday(static_cast(m)); } } } diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index 1b8cb517..ff873e37 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -142,15 +142,15 @@ namespace etl //*********************************************************************** /// Returns true if the year is within the valid -32767 to 32767 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { - return (value >= -32767) && (value <= 32767); + return (value != -32768); } //*********************************************************************** /// The minimum year value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::year min() ETL_NOEXCEPT { return etl::chrono::year(-32767); } @@ -158,7 +158,7 @@ namespace etl //*********************************************************************** /// The maximum year value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::year max() ETL_NOEXCEPT { return etl::chrono::year(32767); } @@ -166,7 +166,7 @@ namespace etl //*********************************************************************** /// Returns true if the year is a leap year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT + ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT { return ((value % 4) == 0) && !((value % 400) == 0); } @@ -187,7 +187,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) == static_cast(y2)); } @@ -195,7 +195,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return !(y1 == y2); } @@ -203,7 +203,7 @@ namespace etl //*********************************************************************** /// Less-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) < static_cast(y2)); } @@ -211,7 +211,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) <= static_cast(y2)); } @@ -219,7 +219,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) > static_cast(y2)); } @@ -227,7 +227,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) >= static_cast(y2)); } @@ -246,7 +246,7 @@ namespace etl /// Add etl::chrono::years to etl::chrono::year ///\return etl::chrono::year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT { etl::chrono::year result(y); @@ -259,7 +259,7 @@ namespace etl /// Add etl::chrono::year to etl::chrono::years ///\return etl::chrono::year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT { etl::chrono::year result(y); @@ -272,7 +272,7 @@ namespace etl /// Subtract etl::chrono::years from etl::chrono::year ///\return etl::chrono::year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT { etl::chrono::year result(y); @@ -285,7 +285,7 @@ namespace etl /// Subtract etl::chrono::year from etl::chrono::year ///\return etl::chrono::years //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return etl::chrono::years(static_cast(static_cast(y1)) - static_cast(static_cast(y2))); diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp index 0594ea75..c4cbe05d 100644 --- a/test/test_chrono_weekday.cpp +++ b/test/test_chrono_weekday.cpp @@ -30,13 +30,12 @@ SOFTWARE. #include "etl/platform.h" -#if ETL_USING_CPP20 - #include "unit_test_framework.h" #include "etl/chrono.h" #include + #include #include @@ -47,129 +46,138 @@ namespace //************************************************************************* TEST(test_default_constructor) { - std::chrono::weekday std_weekday; etl::chrono::weekday weekday; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); + CHECK_FALSE(weekday.ok()); } //************************************************************************* TEST(test_constructor_in_range) { - for (unsigned i = 0U; i < 256U; ++i) + for (unsigned i = 0U; i < 7U; ++i) { - std::chrono::weekday std_weekday(i); etl::chrono::weekday weekday(i); - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(i, weekday.c_encoding()); + CHECK_EQUAL((i == 0U) ? 7U : i, weekday.iso_encoding()); } } //************************************************************************* - TEST(test_encodings) + TEST(test_constructor_out_of_range) { - std::chrono::weekday std_weekday; - etl::chrono::weekday weekday; - - for (unsigned i = 0U; i < 256; ++i) + for (unsigned i = 8U; i < 256U; ++i) { - std_weekday = std::chrono::weekday(i); - weekday = etl::chrono::weekday(i); + etl::chrono::weekday weekday(i); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); - CHECK_EQUAL(std_weekday.iso_encoding(), weekday.iso_encoding()); + CHECK_FALSE(weekday.ok()); + CHECK_EQUAL(i, weekday.c_encoding()); + CHECK_EQUAL((i == 0U) ? 7U : i, weekday.iso_encoding()); } } //************************************************************************* TEST(test_pre_increment) { - std::chrono::weekday std_weekday(0); etl::chrono::weekday weekday(0); + unsigned count = 0; for (int i = 0; i < 255; ++i) { - ++std_weekday; ++weekday; + ++count; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_post_increment) { - std::chrono::weekday std_weekday(0); etl::chrono::weekday weekday(0); + unsigned count = 0; - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 255; ++i) { - std::chrono::weekday std_last_weekday = std_weekday++; - etl::chrono::weekday last_weekday = weekday++; + etl::chrono::weekday last_weekday = weekday++; + unsigned last_count = count++; - CHECK_EQUAL(std_last_weekday.ok(), last_weekday.ok()); - CHECK_EQUAL(std_last_weekday.c_encoding(), last_weekday.c_encoding()); + CHECK_TRUE(last_weekday.ok()); + CHECK_EQUAL(last_count % 7, last_weekday.c_encoding()); + CHECK_EQUAL((last_count % 7 == 0U) ? 7U : last_count % 7, last_weekday.iso_encoding()); - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_pre_decrement) { - std::chrono::weekday std_weekday(255); - etl::chrono::weekday weekday(255); + etl::chrono::weekday weekday(255U); + unsigned count = 255U; - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 255; ++i) { - --std_weekday; --weekday; + --count; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_post_decrement) { - std::chrono::weekday std_weekday(255); - etl::chrono::weekday weekday(255); + etl::chrono::weekday weekday(255U); + unsigned count = 255U; - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 255; ++i) { - std::chrono::weekday std_last_weekday = std_weekday--; etl::chrono::weekday last_weekday = weekday--; + unsigned last_count = count--; - CHECK_EQUAL(std_last_weekday.ok(), last_weekday.ok()); - CHECK_EQUAL(std_last_weekday.c_encoding(), last_weekday.c_encoding()); + if (last_count == 255U) + { + CHECK_FALSE(last_weekday.ok()); + CHECK_EQUAL(255U, last_weekday.c_encoding()); + CHECK_EQUAL(255U, last_weekday.iso_encoding()); + } + else + { + CHECK_TRUE(last_weekday.ok()); + CHECK_EQUAL(last_count % 7, last_weekday.c_encoding()); + CHECK_EQUAL((last_count % 7 == 0U) ? 7U : last_count % 7, last_weekday.iso_encoding()); + } - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_plus_equal_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday += days; - std_weekday += std_days; - weekday += days; + unsigned expected = (wd + ds) % 7; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -177,21 +185,19 @@ namespace //************************************************************************* TEST(test_weekday_plus_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday = weekday + days; - std_weekday = std_weekday + std_days; - weekday = weekday + days; + unsigned expected = (wd + ds) % 7; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -199,21 +205,19 @@ namespace //************************************************************************* TEST(test_days_plus_weekday) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday = weekday + days; - std_weekday = std_days + std_weekday; - weekday = days + weekday; + unsigned expected = (ds + wd) % 7; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -221,21 +225,19 @@ namespace //************************************************************************* TEST(test_minus_equal_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday -= days; - std_weekday -= std_days; - weekday -= days; + unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -243,21 +245,19 @@ namespace //************************************************************************* TEST(test_weekday_minus_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday = weekday - days; - std_weekday = std_weekday - std_days; - weekday = weekday - days; + unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -265,20 +265,20 @@ namespace //************************************************************************* TEST(test_weekday_minus_weekday) { - for (int m = 0; m < 256; ++m) + for (int m = 0; m < 7; ++m) { + etl::chrono::weekday weekday1(m); + etl::chrono::weekday weekday2(7 - m); + std::chrono::weekday std_weekday1(m); - std::chrono::weekday std_weekday2(255 - m); - - std::chrono::weekday weekday1(m); - std::chrono::weekday weekday2(255 - m); - - auto std_days12 = std_weekday1 - std_weekday2; - auto std_days21 = std_weekday2 - std_weekday1; + std::chrono::weekday std_weekday2(7 - m); auto days12 = weekday1 - weekday2; auto days21 = weekday2 - weekday1; + auto std_days12 = std_weekday1 - std_weekday2; + auto std_days21 = std_weekday2 - std_weekday1; + CHECK_EQUAL(std_days12.count(), days12.count()); CHECK_EQUAL(std_days21.count(), days21.count()); } @@ -292,7 +292,19 @@ namespace } //************************************************************************* - TEST(test_literal_weekday) + TEST(test_weekday_constants) + { + CHECK_EQUAL(0U, etl::chrono::Sunday.c_encoding()); + CHECK_EQUAL(1U, etl::chrono::Monday.c_encoding()); + CHECK_EQUAL(2U, etl::chrono::Tuesday.c_encoding()); + CHECK_EQUAL(3U, etl::chrono::Wednesday.c_encoding()); + CHECK_EQUAL(4U, etl::chrono::Thursday.c_encoding()); + CHECK_EQUAL(5U, etl::chrono::Friday.c_encoding()); + CHECK_EQUAL(6U, etl::chrono::Saturday.c_encoding()); + } + + //************************************************************************* + TEST(test_weekday_literals) { using namespace etl::literals::chrono_literals; @@ -324,28 +336,28 @@ namespace //************************************************************************* TEST(test_weekday_comparison_operators) { - etl::chrono::weekday weekday1(1); - etl::chrono::weekday weekday2(2); + etl::chrono::weekday weekday1(1); + etl::chrono::weekday weekday2(2); - CHECK_TRUE(weekday1 == weekday1); - CHECK_FALSE(weekday1 != weekday1); - CHECK_TRUE(weekday1 < weekday2); - CHECK_FALSE(weekday1 < weekday1); - CHECK_FALSE(weekday2 < weekday1); - CHECK_TRUE(weekday1 <= weekday2); - CHECK_TRUE(weekday1 <= weekday1); - CHECK_FALSE(weekday2 <= weekday1); - CHECK_FALSE(weekday1 > weekday2); - CHECK_FALSE(weekday1 > weekday1); - CHECK_TRUE(weekday2 > weekday1); - CHECK_FALSE(weekday1 >= weekday2); - CHECK_TRUE(weekday1 >= weekday1); - CHECK_TRUE(weekday2 >= weekday1); + CHECK_TRUE(weekday1 == weekday1); + CHECK_FALSE(weekday1 != weekday1); + CHECK_TRUE(weekday1 < weekday2); + CHECK_FALSE(weekday1 < weekday1); + CHECK_FALSE(weekday2 < weekday1); + CHECK_TRUE(weekday1 <= weekday2); + CHECK_TRUE(weekday1 <= weekday1); + CHECK_FALSE(weekday2 <= weekday1); + CHECK_FALSE(weekday1 > weekday2); + CHECK_FALSE(weekday1 > weekday1); + CHECK_TRUE(weekday2 > weekday1); + CHECK_FALSE(weekday1 >= weekday2); + CHECK_TRUE(weekday1 >= weekday1); + CHECK_TRUE(weekday2 >= weekday1); #if ETL_USING_CPP20 - CHECK_TRUE((weekday1 <=> weekday1) == 0); - CHECK_TRUE((weekday1 <=> weekday2) < 0); - CHECK_TRUE((weekday2 <=> weekday1) > 0); + CHECK_TRUE((weekday1 <=> weekday1) == 0); + CHECK_TRUE((weekday1 <=> weekday2) < 0); + CHECK_TRUE((weekday2 <=> weekday1) > 0); #endif } @@ -363,24 +375,5 @@ namespace (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(256U, hashes.size()); } - - //************************************************************************* - TEST(test_weekday_types) - { - CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); - CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); - CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); - CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); - CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); - CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); - CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); - CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); - CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); - CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); - CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); - CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); - } }; } - -#endif \ No newline at end of file diff --git a/test/test_chrono_year.cpp b/test/test_chrono_year.cpp index e927668f..dacb9c06 100644 --- a/test/test_chrono_year.cpp +++ b/test/test_chrono_year.cpp @@ -37,6 +37,7 @@ SOFTWARE. #include "etl/chrono.h" #include +#include namespace { @@ -59,24 +60,25 @@ namespace std::chrono::year std_year(i); etl::chrono::year year(i); - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(i, int(year)); } } //************************************************************************* TEST(test_pre_increment) { - std::chrono::year std_year(-32767); etl::chrono::year year(-32767); + int count = int(year); - for (int32_t i = 0; i < 65536; ++i) + for (int32_t i = 0; i < 65534; ++i) { - ++std_year; - ++year; + ++count; + etl::chrono::year this_year = ++year; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(count, year); + CHECK_EQUAL(this_year, year); } }