mirror of
https://github.com/ETLCPP/etl.git
synced 2026-05-01 03:19:10 +08:00
Merge branch 'feature/#757-Add-time-date-classes' of https://github.com/ETLCPP/etl into feature/#757-Add-time-date-classes
This commit is contained in:
commit
c509333c1f
@ -35,7 +35,9 @@ SOFTWARE.
|
||||
|
||||
#include "private/chrono/duration.h"
|
||||
#include "private/chrono/day.h"
|
||||
#include "private/chrono/weekday.h"
|
||||
#include "private/chrono/month.h"
|
||||
#include "private/chrono/year.h"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -240,11 +240,35 @@ SOFTWARE.
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Indicate if etl::literals::chrono_literals has month (_m)
|
||||
#if defined(ETL_ENABLE_CHRONO_LITERALS_MONTH)
|
||||
#define ETL_HAS_CHRONO_LITERALS_MONTH 1
|
||||
// Indicate if etl::literals::chrono_literals has weekdays (_day)
|
||||
#if defined(ETL_DISABLE_CHRONO_LITERALS_WEEKDAY)
|
||||
#define ETL_HAS_CHRONO_LITERALS_DAY 0
|
||||
#else
|
||||
#define ETL_HAS_CHRONO_LITERALS_DAY 1
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Indicate if etl::literals::chrono_literals has weekdays (_weekday)
|
||||
#if defined(ETL_DISABLE_CHRONO_LITERALS_WEEKDAY)
|
||||
#define ETL_HAS_CHRONO_LITERALS_WEEKDAY 0
|
||||
#else
|
||||
#define ETL_HAS_CHRONO_LITERALS_WEEKDAY 1
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Indicate if etl::literals::chrono_literals has month (_month)
|
||||
#if defined(ETL_DISABLE_CHRONO_LITERALS_MONTH)
|
||||
#define ETL_HAS_CHRONO_LITERALS_MONTH 0
|
||||
#else
|
||||
#define ETL_HAS_CHRONO_LITERALS_MONTH 1
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Indicate if etl::literals::chrono_literals has year (_year)
|
||||
#if defined(ETL_DISABLE_CHRONO_LITERALS_YEAR)
|
||||
#define ETL_HAS_CHRONO_LITERALS_YEAR 0
|
||||
#else
|
||||
#define ETL_HAS_CHRONO_LITERALS_YEAR 1
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
@ -484,7 +508,10 @@ namespace etl
|
||||
static ETL_CONSTANT bool has_mutable_array_view = (ETL_HAS_MUTABLE_ARRAY_VIEW == 1);
|
||||
static ETL_CONSTANT bool has_ideque_repair = (ETL_HAS_IDEQUE_REPAIR == 1);
|
||||
static ETL_CONSTANT bool has_virtual_messages = (ETL_HAS_VIRTUAL_MESSAGES == 1);
|
||||
static ETL_CONSTANT bool has_chrono_literals_day = (ETL_HAS_CHRONO_LITERALS_DAY == 1);
|
||||
static ETL_CONSTANT bool has_chrono_literals_weekday = (ETL_HAS_CHRONO_LITERALS_WEEKDAY == 1);
|
||||
static ETL_CONSTANT bool has_chrono_literals_month = (ETL_HAS_CHRONO_LITERALS_MONTH == 1);
|
||||
static ETL_CONSTANT bool has_chrono_literals_year = (ETL_HAS_CHRONO_LITERALS_YEAR == 1);
|
||||
|
||||
// Is...
|
||||
static ETL_CONSTANT bool is_debug_build = (ETL_IS_DEBUG_BUILD == 1);
|
||||
|
||||
@ -182,55 +182,6 @@ namespace etl
|
||||
unsigned char value;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::days to etl::chrono::day
|
||||
///\return etl::chrono::day
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result += ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::day to etl::chrono::days
|
||||
///\return etl::chrono::day
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result += ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::days from etl::chrono::day
|
||||
///\return etl::chrono::day
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result -= ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::day from etl::chrono::day
|
||||
///\return etl::chrono::days
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::days(static_cast<int>(static_cast<unsigned>(d1)) -
|
||||
static_cast<int>(static_cast<unsigned>(d2)));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
@ -288,6 +239,55 @@ namespace etl
|
||||
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::days to etl::chrono::day
|
||||
///\return etl::chrono::day
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result += ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::day to etl::chrono::days
|
||||
///\return etl::chrono::day
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result += ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::days from etl::chrono::day
|
||||
///\return etl::chrono::day
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result -= ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::day from etl::chrono::day
|
||||
///\return etl::chrono::days
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::days(static_cast<int>(static_cast<unsigned>(d1)) -
|
||||
static_cast<int>(static_cast<unsigned>(d2)));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -308,6 +308,7 @@ namespace etl
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ETL_HAS_CHRONO_LITERALS_DAY
|
||||
#if ETL_USING_CPP11
|
||||
namespace etl
|
||||
{
|
||||
@ -318,7 +319,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Literal for days
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR etl::chrono::day operator ""_day(unsigned long long d) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::day(static_cast<unsigned>(d));
|
||||
}
|
||||
@ -326,5 +327,6 @@ namespace etl
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -190,71 +190,6 @@ namespace etl
|
||||
unsigned char value;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::months to etl::chrono::month
|
||||
///\return etl::chrono::month
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT
|
||||
{
|
||||
unsigned int value = static_cast<unsigned int>(m);
|
||||
|
||||
value = value % 12U;
|
||||
|
||||
if (value == 0U)
|
||||
{
|
||||
value = 12U;
|
||||
}
|
||||
|
||||
int delta = ms.count() % 12;
|
||||
|
||||
// Adjust to allow a limited +-11 month delta
|
||||
value += 11U;
|
||||
value += delta;
|
||||
value %= 12U;
|
||||
++value;
|
||||
|
||||
return etl::chrono::month(value);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::month to etl::chrono::months
|
||||
///\return etl::chrono::month
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT
|
||||
{
|
||||
return m + ms;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::months from etl::chrono::month
|
||||
///\return etl::chrono::month
|
||||
//***********************************************************************
|
||||
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());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::month from etl::chrono::month
|
||||
///\return etl::chrono::months
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT
|
||||
{
|
||||
if (m1.ok() && m2.ok())
|
||||
{
|
||||
etl::chrono::months ms(static_cast<signed>(static_cast<unsigned>(m1)) -
|
||||
static_cast<signed>(static_cast<unsigned>(m2)) % 12);
|
||||
|
||||
if (m1 == (m2 + ms))
|
||||
{
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return etl::chrono::months();
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
@ -313,6 +248,70 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::months to etl::chrono::month
|
||||
///\return etl::chrono::month
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT
|
||||
{
|
||||
unsigned int value = static_cast<unsigned int>(m);
|
||||
|
||||
value = value % 12U;
|
||||
|
||||
if (value == 0U)
|
||||
{
|
||||
value = 12U;
|
||||
}
|
||||
|
||||
int delta = ms.count() % 12;
|
||||
|
||||
// Adjust to allow a limited +-11 month delta
|
||||
value += 11U;
|
||||
value += delta;
|
||||
value %= 12U;
|
||||
++value;
|
||||
|
||||
return etl::chrono::month(value);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::month to etl::chrono::months
|
||||
///\return etl::chrono::month
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT
|
||||
{
|
||||
return m + ms;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::months from etl::chrono::month
|
||||
///\return etl::chrono::month
|
||||
//***********************************************************************
|
||||
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());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::month from etl::chrono::month
|
||||
///\return etl::chrono::months
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT
|
||||
{
|
||||
if (m1.ok() && m2.ok())
|
||||
{
|
||||
etl::chrono::months ms(static_cast<signed>(static_cast<unsigned>(m1)) -
|
||||
static_cast<signed>(static_cast<unsigned>(m2)) % 12);
|
||||
|
||||
if (m1 == (m2 + ms))
|
||||
{
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
|
||||
return etl::chrono::months();
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
inline constexpr etl::chrono::month January{ 1 };
|
||||
inline constexpr etl::chrono::month February{ 2 };
|
||||
@ -326,8 +325,7 @@ namespace etl
|
||||
inline constexpr etl::chrono::month October{ 10 };
|
||||
inline constexpr etl::chrono::month November{ 11 };
|
||||
inline constexpr etl::chrono::month December{ 12 };
|
||||
#else
|
||||
|
||||
#else
|
||||
static ETL_CONSTANT etl::chrono::month January{ 1 };
|
||||
static ETL_CONSTANT etl::chrono::month February{ 2 };
|
||||
static ETL_CONSTANT etl::chrono::month March{ 3 };
|
||||
@ -372,7 +370,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Literal for months
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::month operator ""_m(unsigned long long m) ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR etl::chrono::month operator ""_month(unsigned long long m) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::month(m);
|
||||
}
|
||||
|
||||
391
include/etl/private/chrono/weekday.h
Normal file
391
include/etl/private/chrono/weekday.h
Normal file
@ -0,0 +1,391 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2023 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_WEEKDAY_INCLUDED
|
||||
#define ETL_CHRONO_WEEKDAY_INCLUDED
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../hash.h"
|
||||
|
||||
#include "duration.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace chrono
|
||||
{
|
||||
class weekday;
|
||||
|
||||
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::days& ds, const etl::chrono::weekday& m) ETL_NOEXCEPT;
|
||||
ETL_CONSTEXPR etl::chrono::weekday operator -(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT;
|
||||
|
||||
//***********************************************************************
|
||||
/// weekday
|
||||
//***********************************************************************
|
||||
class weekday
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************************************************
|
||||
/// Default constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday()
|
||||
: value(255U)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Construct from unsigned
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR explicit weekday(unsigned value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Copy constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday(const etl::chrono::weekday& other)
|
||||
: value(other.value)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Assignment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday& operator =(const etl::chrono::weekday& rhs)
|
||||
{
|
||||
value = rhs.value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Pre-increment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday& operator ++() ETL_NOEXCEPT
|
||||
{
|
||||
*this += etl::chrono::days(1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Post-increment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::weekday operator ++(int) ETL_NOEXCEPT
|
||||
{
|
||||
const etl::chrono::weekday temp = *this;
|
||||
|
||||
*this += etl::chrono::days(1);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Pre-decrement operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday& operator --() ETL_NOEXCEPT
|
||||
{
|
||||
*this -= etl::chrono::days(1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Post-decrement operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::weekday operator --(int) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::weekday temp = *this;
|
||||
|
||||
*this -= etl::chrono::days(1);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Plus-equals operator adding etl::chrono::days
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday& operator +=(const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
*this = *this + ds;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Minus-equals operator subtracting etl::chrono::days
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday& operator -=(const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
*this = *this - ds;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the weekday is within the valid 1 to 31 range
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return (c_encoding() <= 6U);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// The minimum weekday value for which ok() will return <b>true</b>
|
||||
//***********************************************************************
|
||||
static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday min() ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::weekday(0);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// The maximum weekday value for which ok() will return <b>true</b>
|
||||
//***********************************************************************
|
||||
static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday max() ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::weekday(6);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Get the C encoding of the weekday
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR unsigned c_encoding() const ETL_NOEXCEPT
|
||||
{
|
||||
return (value == 7U) ? 0U : value;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Get the ISO encoding of the weekday
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR unsigned iso_encoding() const ETL_NOEXCEPT
|
||||
{
|
||||
return (value == 0U) ? 7U : value;
|
||||
}
|
||||
|
||||
////***********************************************************************
|
||||
///// Index operator
|
||||
////***********************************************************************
|
||||
//ETL_CONSTEXPR etl::chrono::weekday_indexed operator[](unsigned index) const ETL_NOEXCEPT
|
||||
//{
|
||||
// etl::chrono::weekday_indexed();
|
||||
//}
|
||||
//
|
||||
////***********************************************************************
|
||||
///// Index operator
|
||||
////***********************************************************************
|
||||
//ETL_CONSTEXPR etl::chrono::weekday_last operator[](etl::chrono::last_spec) const ETL_NOEXCEPT
|
||||
//{
|
||||
// std::chrono::weekday_last();
|
||||
//}
|
||||
|
||||
private:
|
||||
|
||||
unsigned char value;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() == wd2.c_encoding());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Inequality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(wd1 == wd2);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Less-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() < wd2.c_encoding());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Less-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() <= wd2.c_encoding());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Greater-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() > wd2.c_encoding());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Greater-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() >= wd2.c_encoding());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Spaceship operator
|
||||
//***********************************************************************
|
||||
#if ETL_USING_CPP20
|
||||
constexpr auto operator <=>(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) noexcept
|
||||
{
|
||||
return (wd1.c_encoding() <=> wd2.c_encoding());
|
||||
}
|
||||
#endif
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::days to etl::chrono::weekday
|
||||
///\return etl::chrono::weekday
|
||||
//***********************************************************************
|
||||
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;
|
||||
|
||||
// Adjust to allow a limited +-7 weekday delta
|
||||
value += 7U;
|
||||
value += delta;
|
||||
value %= 7U;
|
||||
|
||||
return etl::chrono::weekday(value);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::weekday to etl::chrono::days
|
||||
///\return etl::chrono::weekday
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& wd) ETL_NOEXCEPT
|
||||
{
|
||||
return wd + ds;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::days from etl::chrono::weekday
|
||||
///\return etl::chrono::weekday
|
||||
//***********************************************************************
|
||||
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());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::weekday from etl::chrono::weekday
|
||||
///\return etl::chrono::days
|
||||
//***********************************************************************
|
||||
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<signed>(wd1.c_encoding()) -
|
||||
static_cast<signed>(wd2.c_encoding()) % 12);
|
||||
|
||||
if (wd1 == (wd2 + ds))
|
||||
{
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
return etl::chrono::days();
|
||||
}
|
||||
|
||||
#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 };
|
||||
#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 };
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function for etl::chrono::weekday
|
||||
//*************************************************************************
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
template <>
|
||||
struct hash<etl::chrono::weekday>
|
||||
{
|
||||
size_t operator()(const etl::chrono::weekday& wd) const
|
||||
{
|
||||
unsigned value = wd.c_encoding();
|
||||
const uint8_t* p = reinterpret_cast<const uint8_t*>(&value);
|
||||
|
||||
return etl::private_hash::generic_hash<size_t>(p, p + sizeof(unsigned));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ETL_HAS_CHRONO_LITERALS_WEEKDAY
|
||||
#if ETL_USING_CPP11
|
||||
namespace etl
|
||||
{
|
||||
namespace literals
|
||||
{
|
||||
namespace chrono_literals
|
||||
{
|
||||
//***********************************************************************
|
||||
/// Literal for weekdays
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday operator ""_weekday(unsigned long long m) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::weekday(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -190,55 +190,6 @@ namespace etl
|
||||
int16_t value;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::years to etl::chrono::year
|
||||
///\return etl::chrono::year
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
result += ys;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::year to etl::chrono::years
|
||||
///\return etl::chrono::year
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
result += ys;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::years from etl::chrono::year
|
||||
///\return etl::chrono::year
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
result -= ys;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::year from etl::chrono::year
|
||||
///\return etl::chrono::years
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::years(static_cast<int>(static_cast<unsigned>(y1)) -
|
||||
static_cast<int>(static_cast<unsigned>(y2)));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
@ -296,6 +247,55 @@ namespace etl
|
||||
return (static_cast<unsigned>(y1) <=> static_cast<unsigned>(y2));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::years to etl::chrono::year
|
||||
///\return etl::chrono::year
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
result += ys;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Add etl::chrono::year to etl::chrono::years
|
||||
///\return etl::chrono::year
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
result += ys;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::years from etl::chrono::year
|
||||
///\return etl::chrono::year
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
result -= ys;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Subtract etl::chrono::year from etl::chrono::year
|
||||
///\return etl::chrono::years
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::years(static_cast<int>(static_cast<unsigned>(y1)) -
|
||||
static_cast<int>(static_cast<unsigned>(y2)));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -316,6 +316,7 @@ namespace etl
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ETL_HAS_CHRONO_LITERALS_YEAR
|
||||
#if ETL_USING_CPP11
|
||||
namespace etl
|
||||
{
|
||||
@ -326,7 +327,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Literal for years
|
||||
//***********************************************************************
|
||||
constexpr etl::chrono::year operator ""_y(unsigned long long y) noexcept
|
||||
constexpr etl::chrono::year operator ""_year(unsigned long long y) noexcept
|
||||
{
|
||||
return etl::chrono::year(static_cast<int16_t>(y));
|
||||
}
|
||||
@ -334,5 +335,6 @@ namespace etl
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -47,6 +47,9 @@ add_executable(etl_tests
|
||||
test_checksum.cpp
|
||||
|
||||
test_chrono_day.cpp
|
||||
test_chrono_weekday.cpp
|
||||
test_chrono_month.cpp
|
||||
test_chrono_year.cpp
|
||||
|
||||
test_circular_buffer.cpp
|
||||
test_circular_buffer_external_buffer.cpp
|
||||
|
||||
@ -74,8 +74,6 @@ SOFTWARE.
|
||||
#define ETL_POLYMORPHIC_VECTOR
|
||||
#define ETL_POLYMORPHIC_INDIRECT_VECTOR
|
||||
|
||||
#define ETL_ENABLE_CHRONO_LITERALS_MONTH
|
||||
|
||||
#if defined(ETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||
#define ETL_FUNCTION_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_PRIORITY_QUEUE_FORCE_CPP03_IMPLEMENTATION
|
||||
|
||||
@ -37,6 +37,8 @@ SOFTWARE.
|
||||
#include "etl/chrono.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -156,94 +158,110 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_day_plus_days)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
for (int d = 0; d < 256; ++d)
|
||||
{
|
||||
std_day = std_day + std_days;
|
||||
day = day + days;
|
||||
for (int ds = 0; ds < 256; ++ds)
|
||||
{
|
||||
std::chrono::day std_day(d);
|
||||
etl::chrono::day day(d);
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
std::chrono::days std_days(ds);
|
||||
etl::chrono::days days(ds);
|
||||
|
||||
std_day = std_day + std_days;
|
||||
day = day + days;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_days_plus_day)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
for (int d = 0; d < 256; ++d)
|
||||
{
|
||||
std_day = std_days + std_day;
|
||||
day = days + day;
|
||||
for (int ds = 0; ds < 256; ++ds)
|
||||
{
|
||||
std::chrono::day std_day(d);
|
||||
etl::chrono::day day(d);
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
std::chrono::days std_days(ds);
|
||||
etl::chrono::days days(ds);
|
||||
|
||||
std_day = std_days + std_day;
|
||||
day = days + day;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_minus_equal_days)
|
||||
{
|
||||
std::chrono::day std_day(256);
|
||||
etl::chrono::day day(256);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
for (int d = 0; d <= 256; ++d)
|
||||
{
|
||||
std_day -= std_days;
|
||||
day -= days;
|
||||
for (int ds = 0; ds <= 256; ++ds)
|
||||
{
|
||||
std::chrono::day std_day(d);
|
||||
etl::chrono::day day(d);
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
std::chrono::days std_days(ds);
|
||||
etl::chrono::days days(ds);
|
||||
|
||||
std_day -= std_days;
|
||||
day -= days;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_minus_days)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
for (int d = 0; d <= 256; ++d)
|
||||
{
|
||||
std_day = std_day - std_days;
|
||||
day = day - days;
|
||||
for (int ds = 0; ds <= 256; ++ds)
|
||||
{
|
||||
std::chrono::day std_day(d);
|
||||
etl::chrono::day day(d);
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
std::chrono::days std_days(ds);
|
||||
etl::chrono::days days(ds);
|
||||
|
||||
std_day = std_day - std_days;
|
||||
day = day - days;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_minus_day)
|
||||
{
|
||||
for (int i = 1; i < 31; ++i)
|
||||
for (int d = 0; d < 256; ++d)
|
||||
{
|
||||
std::chrono::day std_day1(i);
|
||||
std::chrono::day std_day2(31 - i);
|
||||
std::chrono::day std_day1(d);
|
||||
std::chrono::day std_day2(255 - d);
|
||||
|
||||
etl::chrono::day day1(i);
|
||||
etl::chrono::day day2(31 - i);
|
||||
std::chrono::day day1(d);
|
||||
std::chrono::day day2(255 - d);
|
||||
|
||||
std::chrono::days std_days = std_day1 - std_day2;
|
||||
etl::chrono::days days = day1 - day2;
|
||||
auto std_days12 = std_day1 - std_day2;
|
||||
auto std_days21 = std_day2 - std_day1;
|
||||
|
||||
CHECK_EQUAL(std_days.count(), days.count());
|
||||
auto days12 = day1 - day2;
|
||||
auto days21 = day2 - day1;
|
||||
|
||||
CHECK_EQUAL(std_days12.count(), days12.count());
|
||||
CHECK_EQUAL(std_days21.count(), days21.count());
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,7 +279,7 @@ namespace
|
||||
using namespace etl::literals::chrono_literals;
|
||||
|
||||
std::chrono::day std_day = 25d;
|
||||
etl::chrono::day day = 25_d;
|
||||
etl::chrono::day day = 25_day;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
@ -296,15 +314,18 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_hash)
|
||||
TEST(test_day_hashes_are_unique)
|
||||
{
|
||||
etl::chrono::day day(10);
|
||||
std::vector<size_t> hashes;
|
||||
|
||||
size_t h = 0;
|
||||
|
||||
h = etl::hash<etl::chrono::day>()(day);
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
hashes.push_back(etl::hash<etl::chrono::day>()(etl::chrono::day(i)));
|
||||
}
|
||||
|
||||
CHECK_TRUE(h != 0);
|
||||
std::sort(hashes.begin(), hashes.end());
|
||||
(void)std::unique(hashes.begin(), hashes.end());
|
||||
CHECK_EQUAL(256U, hashes.size());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -37,6 +37,8 @@ SOFTWARE.
|
||||
#include "etl/chrono.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -86,7 +88,7 @@ namespace
|
||||
std::chrono::month std_month(0);
|
||||
etl::chrono::month month(0);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
std::chrono::month std_last_month = std_month++;
|
||||
etl::chrono::month last_month = month++;
|
||||
@ -102,10 +104,10 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_pre_decrement)
|
||||
{
|
||||
std::chrono::month std_month(256);
|
||||
etl::chrono::month month(256);
|
||||
std::chrono::month std_month(255);
|
||||
etl::chrono::month month(255);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
--std_month;
|
||||
--month;
|
||||
@ -121,131 +123,150 @@ namespace
|
||||
std::chrono::month std_month(255);
|
||||
etl::chrono::month month(255);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
std::chrono::month std_last_month = std_month--;
|
||||
etl::chrono::month last_month = month--;
|
||||
|
||||
// CHECK_EQUAL(std_last_month.ok(), last_month.ok());
|
||||
CHECK_EQUAL(std_last_month.ok(), last_month.ok());
|
||||
CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month));
|
||||
|
||||
// CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
}
|
||||
}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(test_plus_equal_months)
|
||||
//{
|
||||
// std::chrono::month std_month(0);
|
||||
// etl::chrono::month month(0);
|
||||
//*************************************************************************
|
||||
TEST(test_plus_equal_months)
|
||||
{
|
||||
for (int m = 0; m <= 12; ++m)
|
||||
{
|
||||
for (int ms = 0; ms <= 24; ++ms)
|
||||
{
|
||||
std::chrono::month std_month(m);
|
||||
etl::chrono::month month(m);
|
||||
|
||||
// std::chrono::months std_months(2);
|
||||
// etl::chrono::months months(2);
|
||||
std::chrono::months std_months(ms);
|
||||
etl::chrono::months months(ms);
|
||||
|
||||
// for (int i = 0; i < 128; ++i)
|
||||
// {
|
||||
// std_month += std_months;
|
||||
// month += months;
|
||||
std_month += std_months;
|
||||
month += months;
|
||||
|
||||
// CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
// CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
// }
|
||||
//}
|
||||
CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(test_month_plus_months)
|
||||
//{
|
||||
// std::chrono::month std_month(0);
|
||||
// etl::chrono::month month(0);
|
||||
//*************************************************************************
|
||||
TEST(test_month_plus_months)
|
||||
{
|
||||
for (int m = 0; m <= 12; ++m)
|
||||
{
|
||||
for (int ms = 0; ms <= 24; ++ms)
|
||||
{
|
||||
std::chrono::month std_month(m);
|
||||
etl::chrono::month month(m);
|
||||
|
||||
// std::chrono::months std_months(2);
|
||||
// etl::chrono::months months(2);
|
||||
std::chrono::months std_months(ms);
|
||||
etl::chrono::months months(ms);
|
||||
|
||||
// for (int i = 0; i < 128; ++i)
|
||||
// {
|
||||
// std_month = std_month + std_months;
|
||||
// month = month + months;
|
||||
std_month = std_month + std_months;
|
||||
month = month + months;
|
||||
|
||||
// CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
// CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
// }
|
||||
//}
|
||||
CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(test_months_plus_month)
|
||||
//{
|
||||
// std::chrono::month std_month(0);
|
||||
// etl::chrono::month month(0);
|
||||
//*************************************************************************
|
||||
TEST(test_months_plus_month)
|
||||
{
|
||||
for (int m = 0; m <= 12; ++m)
|
||||
{
|
||||
for (int ms = 0; ms <= 24; ++ms)
|
||||
{
|
||||
std::chrono::month std_month(m);
|
||||
etl::chrono::month month(m);
|
||||
|
||||
// std::chrono::months std_months(2);
|
||||
// etl::chrono::months months(2);
|
||||
std::chrono::months std_months(ms);
|
||||
etl::chrono::months months(ms);
|
||||
|
||||
// for (int i = 0; i < 128; ++i)
|
||||
// {
|
||||
// std_month = std_months + std_month;
|
||||
// month = months + month;
|
||||
std_month = std_months + std_month;
|
||||
month = months + month;
|
||||
|
||||
// CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
// CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
// }
|
||||
//}
|
||||
CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(test_minus_equal_months)
|
||||
//{
|
||||
// std::chrono::month std_month(256);
|
||||
// etl::chrono::month month(256);
|
||||
//*************************************************************************
|
||||
TEST(test_minus_equal_months)
|
||||
{
|
||||
for (int m = 0; m <= 12; ++m)
|
||||
{
|
||||
for (int ms = 0; ms <= 24; ++ms)
|
||||
{
|
||||
std::chrono::month std_month(m);
|
||||
etl::chrono::month month(m);
|
||||
|
||||
// std::chrono::months std_months(2);
|
||||
// etl::chrono::months months(2);
|
||||
std::chrono::months std_months(ms);
|
||||
etl::chrono::months months(ms);
|
||||
|
||||
// for (int i = 0; i < 128; ++i)
|
||||
// {
|
||||
// std_month -= std_months;
|
||||
// month -= months;
|
||||
std_month -= std_months;
|
||||
month -= months;
|
||||
|
||||
// CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
// CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
// }
|
||||
//}
|
||||
CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(test_month_minus_months)
|
||||
//{
|
||||
// std::chrono::month std_month(0);
|
||||
// etl::chrono::month month(0);
|
||||
//*************************************************************************
|
||||
TEST(test_month_minus_months)
|
||||
{
|
||||
for (int m = 0; m <= 12; ++m)
|
||||
{
|
||||
for (int ms = 0; ms <= 24; ++ms)
|
||||
{
|
||||
std::chrono::month std_month(m);
|
||||
etl::chrono::month month(m);
|
||||
|
||||
// std::chrono::months std_months(2);
|
||||
// etl::chrono::months months(2);
|
||||
std::chrono::months std_months(ms);
|
||||
etl::chrono::months months(ms);
|
||||
|
||||
// for (int i = 0; i < 128; ++i)
|
||||
// {
|
||||
// std_month = std_month - std_months;
|
||||
// month = month - months;
|
||||
std_month = std_month - std_months;
|
||||
month = month - months;
|
||||
|
||||
// CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
// CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
// }
|
||||
//}
|
||||
CHECK_EQUAL(std_month.ok(), month.ok());
|
||||
CHECK_EQUAL(unsigned(std_month), unsigned(month));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////*************************************************************************
|
||||
//TEST(test_month_minus_month)
|
||||
//{
|
||||
// for (int i = 1; i < 12; ++i)
|
||||
// {
|
||||
// std::chrono::month std_month1(i);
|
||||
// std::chrono::month std_month2(12 - i);
|
||||
//*************************************************************************
|
||||
TEST(test_month_minus_month)
|
||||
{
|
||||
for (int m = 0; m < 256; ++m)
|
||||
{
|
||||
std::chrono::month std_month1(m);
|
||||
std::chrono::month std_month2(255 - m);
|
||||
|
||||
// etl::chrono::month month1(i);
|
||||
// etl::chrono::month month2(12 - i);
|
||||
std::chrono::month month1(m);
|
||||
std::chrono::month month2(255 - m);
|
||||
|
||||
// std::chrono::months std_months = std_month1 - std_month2;
|
||||
// etl::chrono::months months = month1 - month2;
|
||||
auto std_months12 = std_month1 - std_month2;
|
||||
auto std_months21 = std_month2 - std_month1;
|
||||
|
||||
// CHECK_EQUAL(std_months.count(), months.count());
|
||||
// }
|
||||
//}
|
||||
auto months12 = month1 - month2;
|
||||
auto months21 = month2 - month1;
|
||||
|
||||
CHECK_EQUAL(std_months12.count(), months12.count());
|
||||
CHECK_EQUAL(std_months21.count(), months21.count());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_min_max_month)
|
||||
@ -259,18 +280,18 @@ namespace
|
||||
{
|
||||
using namespace etl::literals::chrono_literals;
|
||||
|
||||
etl::chrono::month month1 = 1_m;
|
||||
etl::chrono::month month2 = 2_m;
|
||||
etl::chrono::month month3 = 3_m;
|
||||
etl::chrono::month month4 = 4_m;
|
||||
etl::chrono::month month5 = 5_m;
|
||||
etl::chrono::month month6 = 6_m;
|
||||
etl::chrono::month month7 = 7_m;
|
||||
etl::chrono::month month8 = 8_m;
|
||||
etl::chrono::month month9 = 9_m;
|
||||
etl::chrono::month month10 = 10_m;
|
||||
etl::chrono::month month11 = 11_m;
|
||||
etl::chrono::month month12 = 12_m;
|
||||
etl::chrono::month month1 = 1_month;
|
||||
etl::chrono::month month2 = 2_month;
|
||||
etl::chrono::month month3 = 3_month;
|
||||
etl::chrono::month month4 = 4_month;
|
||||
etl::chrono::month month5 = 5_month;
|
||||
etl::chrono::month month6 = 6_month;
|
||||
etl::chrono::month month7 = 7_month;
|
||||
etl::chrono::month month8 = 8_month;
|
||||
etl::chrono::month month9 = 9_month;
|
||||
etl::chrono::month month10 = 10_month;
|
||||
etl::chrono::month month11 = 11_month;
|
||||
etl::chrono::month month12 = 12_month;
|
||||
|
||||
CHECK_TRUE(month1.ok());
|
||||
CHECK_TRUE(month2.ok());
|
||||
@ -328,15 +349,35 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_month_hash)
|
||||
TEST(test_month_hashes_are_unique)
|
||||
{
|
||||
etl::chrono::month month(10);
|
||||
std::vector<size_t> hashes;
|
||||
|
||||
size_t h = 0;
|
||||
|
||||
h = etl::hash<etl::chrono::month>()(month);
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
hashes.push_back(etl::hash<etl::chrono::month>()(etl::chrono::month(i)));
|
||||
}
|
||||
|
||||
CHECK_TRUE(h != 0);
|
||||
std::sort(hashes.begin(), hashes.end());
|
||||
(void)std::unique(hashes.begin(), hashes.end());
|
||||
CHECK_EQUAL(256U, hashes.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_month_types)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::January), static_cast<unsigned>(etl::chrono::January));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::February), static_cast<unsigned>(etl::chrono::February));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::March), static_cast<unsigned>(etl::chrono::March));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::April), static_cast<unsigned>(etl::chrono::April));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::May), static_cast<unsigned>(etl::chrono::May));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::June), static_cast<unsigned>(etl::chrono::June));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::July), static_cast<unsigned>(etl::chrono::July));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::August), static_cast<unsigned>(etl::chrono::August));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::September), static_cast<unsigned>(etl::chrono::September));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::October), static_cast<unsigned>(etl::chrono::October));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::November), static_cast<unsigned>(etl::chrono::November));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::December), static_cast<unsigned>(etl::chrono::December));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
386
test/test_chrono_weekday.cpp
Normal file
386
test/test_chrono_weekday.cpp
Normal file
@ -0,0 +1,386 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Documentation:
|
||||
|
||||
Copyright(c) 2023 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/platform.h"
|
||||
|
||||
#if ETL_USING_CPP20
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/chrono.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_chrono_weekday)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_constructor)
|
||||
{
|
||||
std::chrono::weekday std_weekday;
|
||||
etl::chrono::weekday weekday;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_in_range)
|
||||
{
|
||||
for (unsigned i = 0U; i < 256U; ++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());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_encodings)
|
||||
{
|
||||
std::chrono::weekday std_weekday;
|
||||
etl::chrono::weekday weekday;
|
||||
|
||||
for (unsigned i = 0U; i < 256; ++i)
|
||||
{
|
||||
std_weekday = std::chrono::weekday(i);
|
||||
weekday = etl::chrono::weekday(i);
|
||||
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
CHECK_EQUAL(std_weekday.iso_encoding(), weekday.iso_encoding());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pre_increment)
|
||||
{
|
||||
std::chrono::weekday std_weekday(0);
|
||||
etl::chrono::weekday weekday(0);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
{
|
||||
++std_weekday;
|
||||
++weekday;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_post_increment)
|
||||
{
|
||||
std::chrono::weekday std_weekday(0);
|
||||
etl::chrono::weekday weekday(0);
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
std::chrono::weekday std_last_weekday = std_weekday++;
|
||||
etl::chrono::weekday last_weekday = weekday++;
|
||||
|
||||
CHECK_EQUAL(std_last_weekday.ok(), last_weekday.ok());
|
||||
CHECK_EQUAL(std_last_weekday.c_encoding(), last_weekday.c_encoding());
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pre_decrement)
|
||||
{
|
||||
std::chrono::weekday std_weekday(255);
|
||||
etl::chrono::weekday weekday(255);
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
--std_weekday;
|
||||
--weekday;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_post_decrement)
|
||||
{
|
||||
std::chrono::weekday std_weekday(255);
|
||||
etl::chrono::weekday weekday(255);
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
std::chrono::weekday std_last_weekday = std_weekday--;
|
||||
etl::chrono::weekday last_weekday = weekday--;
|
||||
|
||||
CHECK_EQUAL(std_last_weekday.ok(), last_weekday.ok());
|
||||
CHECK_EQUAL(std_last_weekday.c_encoding(), last_weekday.c_encoding());
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_plus_equal_days)
|
||||
{
|
||||
for (int wd = 0; wd <= 6; ++wd)
|
||||
{
|
||||
for (int 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);
|
||||
|
||||
std_weekday += std_days;
|
||||
weekday += days;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_weekday_plus_days)
|
||||
{
|
||||
for (int wd = 0; wd <= 6; ++wd)
|
||||
{
|
||||
for (int 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);
|
||||
|
||||
std_weekday = std_weekday + std_days;
|
||||
weekday = weekday + days;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_days_plus_weekday)
|
||||
{
|
||||
for (int wd = 0; wd <= 6; ++wd)
|
||||
{
|
||||
for (int 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);
|
||||
|
||||
std_weekday = std_days + std_weekday;
|
||||
weekday = days + weekday;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_minus_equal_days)
|
||||
{
|
||||
for (int wd = 0; wd <= 6; ++wd)
|
||||
{
|
||||
for (int 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);
|
||||
|
||||
std_weekday -= std_days;
|
||||
weekday -= days;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_weekday_minus_days)
|
||||
{
|
||||
for (int wd = 0; wd <= 6; ++wd)
|
||||
{
|
||||
for (int 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);
|
||||
|
||||
std_weekday = std_weekday - std_days;
|
||||
weekday = weekday - days;
|
||||
|
||||
CHECK_EQUAL(std_weekday.ok(), weekday.ok());
|
||||
CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_weekday_minus_weekday)
|
||||
{
|
||||
for (int m = 0; m < 256; ++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;
|
||||
|
||||
auto days12 = weekday1 - weekday2;
|
||||
auto days21 = weekday2 - weekday1;
|
||||
|
||||
CHECK_EQUAL(std_days12.count(), days12.count());
|
||||
CHECK_EQUAL(std_days21.count(), days21.count());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_min_max_weekday)
|
||||
{
|
||||
CHECK_EQUAL(etl::chrono::Sunday.c_encoding(), etl::chrono::weekday::min().c_encoding());
|
||||
CHECK_EQUAL(etl::chrono::Saturday.c_encoding(), etl::chrono::weekday::max().c_encoding());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_literal_weekday)
|
||||
{
|
||||
using namespace etl::literals::chrono_literals;
|
||||
|
||||
etl::chrono::weekday weekday0 = 0_weekday;
|
||||
etl::chrono::weekday weekday1 = 1_weekday;
|
||||
etl::chrono::weekday weekday2 = 2_weekday;
|
||||
etl::chrono::weekday weekday3 = 3_weekday;
|
||||
etl::chrono::weekday weekday4 = 4_weekday;
|
||||
etl::chrono::weekday weekday5 = 5_weekday;
|
||||
etl::chrono::weekday weekday6 = 6_weekday;
|
||||
|
||||
CHECK_TRUE(weekday0.ok());
|
||||
CHECK_TRUE(weekday1.ok());
|
||||
CHECK_TRUE(weekday2.ok());
|
||||
CHECK_TRUE(weekday3.ok());
|
||||
CHECK_TRUE(weekday4.ok());
|
||||
CHECK_TRUE(weekday5.ok());
|
||||
CHECK_TRUE(weekday6.ok());
|
||||
|
||||
CHECK_EQUAL(0U, weekday0.c_encoding());
|
||||
CHECK_EQUAL(1U, weekday1.c_encoding());
|
||||
CHECK_EQUAL(2U, weekday2.c_encoding());
|
||||
CHECK_EQUAL(3U, weekday3.c_encoding());
|
||||
CHECK_EQUAL(4U, weekday4.c_encoding());
|
||||
CHECK_EQUAL(5U, weekday5.c_encoding());
|
||||
CHECK_EQUAL(6U, weekday6.c_encoding());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_weekday_comparison_operators)
|
||||
{
|
||||
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);
|
||||
|
||||
#if ETL_USING_CPP20
|
||||
CHECK_TRUE((weekday1 <=> weekday1) == 0);
|
||||
CHECK_TRUE((weekday1 <=> weekday2) < 0);
|
||||
CHECK_TRUE((weekday2 <=> weekday1) > 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_weekday_hashes_are_unique)
|
||||
{
|
||||
std::vector<size_t> hashes;
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
hashes.push_back(etl::hash<etl::chrono::weekday>()(etl::chrono::weekday(i)));
|
||||
}
|
||||
|
||||
std::sort(hashes.begin(), hashes.end());
|
||||
(void)std::unique(hashes.begin(), hashes.end());
|
||||
CHECK_EQUAL(256U, hashes.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_weekday_types)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::January), static_cast<unsigned>(etl::chrono::January));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::February), static_cast<unsigned>(etl::chrono::February));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::March), static_cast<unsigned>(etl::chrono::March));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::April), static_cast<unsigned>(etl::chrono::April));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::May), static_cast<unsigned>(etl::chrono::May));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::June), static_cast<unsigned>(etl::chrono::June));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::July), static_cast<unsigned>(etl::chrono::July));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::August), static_cast<unsigned>(etl::chrono::August));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::September), static_cast<unsigned>(etl::chrono::September));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::October), static_cast<unsigned>(etl::chrono::October));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::November), static_cast<unsigned>(etl::chrono::November));
|
||||
CHECK_EQUAL(static_cast<unsigned>(std::chrono::December), static_cast<unsigned>(etl::chrono::December));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -261,7 +261,7 @@ namespace
|
||||
using namespace etl::literals::chrono_literals;
|
||||
|
||||
std::chrono::year std_year = 25y;
|
||||
etl::chrono::year year = 25_y;
|
||||
etl::chrono::year year = 25_year;
|
||||
|
||||
CHECK_EQUAL(std_year.ok(), year.ok());
|
||||
CHECK_EQUAL(int(std_year), int(year));
|
||||
@ -270,7 +270,7 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_year_comparison_operators)
|
||||
{
|
||||
etl::chrono::year year10(-10);
|
||||
etl::chrono::year year10(10);
|
||||
etl::chrono::year year20(20);
|
||||
|
||||
CHECK_TRUE(year10 == year10);
|
||||
@ -296,21 +296,18 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_year_hash)
|
||||
TEST(test_year_hashes_are_unique)
|
||||
{
|
||||
etl::chrono::year year(-32767);
|
||||
std::vector<size_t> hashes;
|
||||
|
||||
size_t h = 0;
|
||||
|
||||
h = etl::hash<etl::chrono::year>()(year);
|
||||
for (int32_t i = -32767; i < 32768; ++i)
|
||||
{
|
||||
hashes.push_back(etl::hash<etl::chrono::year>()(etl::chrono::year(i)));
|
||||
}
|
||||
|
||||
CHECK_TRUE(h != 0);
|
||||
|
||||
year = etl::chrono::year(32767);
|
||||
h = 0;
|
||||
h = etl::hash<etl::chrono::year>()(year);
|
||||
|
||||
CHECK_TRUE(h != 0);
|
||||
std::sort(hashes.begin(), hashes.end());
|
||||
(void)std::unique(hashes.begin(), hashes.end());
|
||||
CHECK_EQUAL(65535U, hashes.size());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -3004,6 +3004,7 @@
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\day.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\duration.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\month.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\year.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\diagnostic_array_bounds_push.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\diagnostic_deprecated_push.h" />
|
||||
@ -14344,6 +14345,7 @@
|
||||
<ClCompile Include="..\test_char_traits.cpp" />
|
||||
<ClCompile Include="..\test_chrono_day.cpp" />
|
||||
<ClCompile Include="..\test_chrono_month.cpp" />
|
||||
<ClCompile Include="..\test_chrono_weekday.cpp" />
|
||||
<ClCompile Include="..\test_chrono_year.cpp" />
|
||||
<ClCompile Include="..\test_circular_buffer.cpp" />
|
||||
<ClCompile Include="..\test_circular_buffer_external_buffer.cpp" />
|
||||
|
||||
@ -1383,6 +1383,9 @@
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\year.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test_string_char.cpp">
|
||||
@ -3455,6 +3458,9 @@
|
||||
<ClCompile Include="..\test_chrono_year.cpp">
|
||||
<Filter>Tests\Chrono</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_chrono_weekday.cpp">
|
||||
<Filter>Tests\Chrono</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user