mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-26 20:38:45 +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
b6e75065f4
@ -31,13 +31,22 @@ SOFTWARE.
|
||||
#ifndef ETL_CHRONO_INCLUDED
|
||||
#define ETL_CHRONO_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#define ETL_IN_CHRONO_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "hash.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "private/chrono/last_spec.h"
|
||||
#include "private/chrono/duration.h"
|
||||
#include "private/chrono/day.h"
|
||||
#include "private/chrono/weekday.h"
|
||||
#include "private/chrono/weekday_indexed.h"
|
||||
#include "private/chrono/weekday_last.h"
|
||||
#include "private/chrono/month.h"
|
||||
#include "private/chrono/year.h"
|
||||
|
||||
|
||||
#undef ETL_IN_CHRONO_H
|
||||
|
||||
#endif
|
||||
|
||||
@ -28,15 +28,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_DAY_INCLUDED
|
||||
#define ETL_CHRONO_DAY_INCLUDED
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../hash.h"
|
||||
|
||||
#include "duration.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef ETL_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -52,7 +46,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Default constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR day()
|
||||
ETL_CONSTEXPR day() ETL_NOEXCEPT
|
||||
: value(0)
|
||||
{
|
||||
}
|
||||
@ -60,7 +54,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Construct from unsigned
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR explicit day(unsigned value_)
|
||||
ETL_CONSTEXPR explicit day(unsigned value_) ETL_NOEXCEPT
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
@ -68,7 +62,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Copy constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR day(const etl::chrono::day& other)
|
||||
ETL_CONSTEXPR day(const etl::chrono::day& other) ETL_NOEXCEPT
|
||||
: value(other.value)
|
||||
{
|
||||
}
|
||||
@ -76,7 +70,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Assignment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::day& rhs)
|
||||
ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::day& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
value = rhs.value;
|
||||
|
||||
@ -148,7 +142,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the day is within the valid 1 to 31 range
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return (value >= 1U) && (value <= 31U);
|
||||
}
|
||||
@ -185,7 +179,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) == static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -193,7 +187,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Inequality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(d1 == d2);
|
||||
}
|
||||
@ -209,7 +203,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Less-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) <= static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -217,7 +211,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) > static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -225,7 +219,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) >= static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -234,7 +228,7 @@ namespace etl
|
||||
/// Spaceship operator
|
||||
//***********************************************************************
|
||||
#if ETL_USING_CPP20
|
||||
constexpr auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2) noexcept
|
||||
[[nodiscard]] constexpr auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2) noexcept
|
||||
{
|
||||
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -244,7 +238,7 @@ namespace etl
|
||||
/// 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_NODISCARD 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 +251,7 @@ namespace etl
|
||||
/// 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_NODISCARD 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 +264,7 @@ namespace etl
|
||||
/// 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_NODISCARD 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 +277,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD 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)));
|
||||
@ -319,7 +313,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Literal for days
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator ""_day(unsigned long long d) ETL_NOEXCEPT
|
||||
constexpr etl::chrono::day operator ""_day(unsigned long long d) noexcept
|
||||
{
|
||||
return etl::chrono::day(static_cast<unsigned>(d));
|
||||
}
|
||||
@ -328,5 +322,3 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -28,10 +28,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_DURATION_INCLUDED
|
||||
#define ETL_CHRONO_DURATION_INCLUDED
|
||||
#ifndef ETL_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../ratio.h"
|
||||
#include "../../static_assert.h"
|
||||
#include "../../limits.h"
|
||||
@ -94,7 +94,7 @@ namespace etl
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR TValue count() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR TValue count() const ETL_NOEXCEPT
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@ -129,11 +129,9 @@ namespace etl
|
||||
/// duration_cast
|
||||
//***********************************************************************
|
||||
template <typename TToDuration, typename TValue, typename TPeriod>
|
||||
ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration<TValue, TPeriod>& d)
|
||||
ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration<TValue, TPeriod>& d) ETL_NOEXCEPT
|
||||
{
|
||||
return TToDuration();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
52
include/etl/private/chrono/last_spec.h
Normal file
52
include/etl/private/chrono/last_spec.h
Normal file
@ -0,0 +1,52 @@
|
||||
///\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_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace chrono
|
||||
{
|
||||
struct last_spec
|
||||
{
|
||||
ETL_CONSTEXPR explicit last_spec()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
inline constexpr last_spec last{};
|
||||
#else
|
||||
static ETL_CONSTANT last_spec last{};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -28,15 +28,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_MONTH_INCLUDED
|
||||
#define ETL_CHRONO_MONTH_INCLUDED
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../hash.h"
|
||||
|
||||
#include "duration.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef ETL_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -58,7 +52,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Default constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR month()
|
||||
ETL_CONSTEXPR month() ETL_NOEXCEPT
|
||||
: value(0)
|
||||
{
|
||||
}
|
||||
@ -66,7 +60,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Construct from unsigned
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR explicit month(unsigned value_)
|
||||
ETL_CONSTEXPR explicit month(unsigned value_) ETL_NOEXCEPT
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
@ -74,7 +68,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Copy constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR month(const etl::chrono::month& other)
|
||||
ETL_CONSTEXPR month(const etl::chrono::month& other) ETL_NOEXCEPT
|
||||
: value(other.value)
|
||||
{
|
||||
}
|
||||
@ -82,7 +76,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Assignment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::month& operator =(const etl::chrono::month& rhs)
|
||||
ETL_CONSTEXPR etl::chrono::month& operator =(const etl::chrono::month& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
value = rhs.value;
|
||||
|
||||
@ -156,7 +150,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the month is within the valid 1 to 31 range
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return (value >= 1U) && (value <= 12U);
|
||||
}
|
||||
@ -190,7 +184,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Normalise to a in-range month
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR void normalise()
|
||||
ETL_NODISCARD ETL_CONSTEXPR void normalise() ETL_NOEXCEPT
|
||||
{
|
||||
value = ((value % 12U) == 0U) ? 12U : value;
|
||||
}
|
||||
@ -201,7 +195,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) == static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -209,7 +203,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Inequality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(d1 == d2);
|
||||
}
|
||||
@ -217,7 +211,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Less-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) < static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -225,7 +219,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Less-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) <= static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -233,7 +227,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) > static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -241,7 +235,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) >= static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -250,7 +244,7 @@ namespace etl
|
||||
/// Spaceship operator
|
||||
//***********************************************************************
|
||||
#if ETL_USING_CPP20
|
||||
constexpr auto operator <=>(const etl::chrono::month& d1, const etl::chrono::month& d2) noexcept
|
||||
[[nodiscard]] constexpr auto operator <=>(const etl::chrono::month& d1, const etl::chrono::month& d2) noexcept
|
||||
{
|
||||
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
|
||||
}
|
||||
@ -260,7 +254,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD 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);
|
||||
|
||||
@ -286,7 +280,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT
|
||||
{
|
||||
return m + ms;
|
||||
}
|
||||
@ -295,7 +289,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD 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());
|
||||
}
|
||||
@ -304,7 +298,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT
|
||||
{
|
||||
if (m1.ok() && m2.ok())
|
||||
{
|
||||
@ -378,7 +372,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Literal for months
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::month operator ""_month(unsigned long long m) ETL_NOEXCEPT
|
||||
constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept
|
||||
{
|
||||
return etl::chrono::month(m);
|
||||
}
|
||||
@ -387,5 +381,3 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -28,21 +28,18 @@ 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>
|
||||
#ifndef ETL_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace chrono
|
||||
{
|
||||
class weekday;
|
||||
class weekday_indexed;
|
||||
class weekday_last;
|
||||
struct last_spec;
|
||||
|
||||
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;
|
||||
@ -58,7 +55,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Default constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday()
|
||||
ETL_CONSTEXPR weekday() ETL_NOEXCEPT
|
||||
: value(255U)
|
||||
{
|
||||
}
|
||||
@ -66,7 +63,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Construct from unsigned
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR explicit weekday(unsigned value_)
|
||||
ETL_CONSTEXPR explicit weekday(unsigned value_) ETL_NOEXCEPT
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
@ -74,7 +71,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Copy constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday(const etl::chrono::weekday& other)
|
||||
ETL_CONSTEXPR weekday(const etl::chrono::weekday& other) ETL_NOEXCEPT
|
||||
: value(other.value)
|
||||
{
|
||||
}
|
||||
@ -82,7 +79,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Assignment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday& operator =(const etl::chrono::weekday& rhs)
|
||||
ETL_CONSTEXPR etl::chrono::weekday& operator =(const etl::chrono::weekday& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
value = rhs.value;
|
||||
|
||||
@ -156,7 +153,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the weekday is within the valid 1 to 31 range
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return (c_encoding() <= 6U);
|
||||
}
|
||||
@ -193,26 +190,20 @@ namespace etl
|
||||
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();
|
||||
//}
|
||||
//***********************************************************************
|
||||
/// Index operator from index
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday_indexed operator[](unsigned index) const ETL_NOEXCEPT;
|
||||
|
||||
//***********************************************************************
|
||||
/// Index operator from etl::chrono::last_spec
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday_last operator[](etl::chrono::last_spec) const ETL_NOEXCEPT;
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the day is a weekend.
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool is_weekend()
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool is_weekend() ETL_NOEXCEPT
|
||||
{
|
||||
return (c_encoding() == 0U) || (c_encoding() == 6U);
|
||||
}
|
||||
@ -222,7 +213,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Normalise to a in-range weekday
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR void normalise()
|
||||
ETL_NODISCARD ETL_CONSTEXPR void normalise() ETL_NOEXCEPT
|
||||
{
|
||||
value %= 7U;
|
||||
}
|
||||
@ -233,7 +224,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() == wd2.c_encoding());
|
||||
}
|
||||
@ -241,7 +232,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Inequality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(wd1 == wd2);
|
||||
}
|
||||
@ -249,7 +240,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Less-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() < wd2.c_encoding());
|
||||
}
|
||||
@ -257,7 +248,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Less-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() <= wd2.c_encoding());
|
||||
}
|
||||
@ -265,7 +256,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() > wd2.c_encoding());
|
||||
}
|
||||
@ -273,7 +264,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.c_encoding() >= wd2.c_encoding());
|
||||
}
|
||||
@ -282,7 +273,7 @@ namespace etl
|
||||
/// Spaceship operator
|
||||
//***********************************************************************
|
||||
#if ETL_USING_CPP20
|
||||
constexpr auto operator <=>(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) noexcept
|
||||
[[nodiscard]] constexpr auto operator <=>(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) noexcept
|
||||
{
|
||||
return (wd1.c_encoding() <=> wd2.c_encoding());
|
||||
}
|
||||
@ -292,7 +283,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday operator +(const etl::chrono::weekday& wd, const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
unsigned int value = wd.c_encoding();
|
||||
|
||||
@ -312,7 +303,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& wd) ETL_NOEXCEPT
|
||||
{
|
||||
return wd + ds;
|
||||
}
|
||||
@ -321,7 +312,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD 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());
|
||||
}
|
||||
@ -330,7 +321,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::days operator -(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
if (wd1.ok() && wd2.ok())
|
||||
{
|
||||
@ -394,7 +385,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Literal for weekdays
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday operator ""_weekday(unsigned long long m) ETL_NOEXCEPT
|
||||
constexpr etl::chrono::weekday operator ""_weekday(unsigned long long m) noexcept
|
||||
{
|
||||
return etl::chrono::weekday(m);
|
||||
}
|
||||
@ -403,5 +394,3 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
151
include/etl/private/chrono/weekday_indexed.h
Normal file
151
include/etl/private/chrono/weekday_indexed.h
Normal file
@ -0,0 +1,151 @@
|
||||
///\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_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace chrono
|
||||
{
|
||||
//***********************************************************************
|
||||
/// weekday_indexed
|
||||
//***********************************************************************
|
||||
class weekday_indexed
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************************************************
|
||||
/// Default constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday_indexed() ETL_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Construct from unsigned
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday_indexed(const etl::chrono::weekday& wd_, unsigned index_) ETL_NOEXCEPT
|
||||
: wd(wd_)
|
||||
, i(index_)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Copy constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday_indexed(const etl::chrono::weekday_indexed& other) ETL_NOEXCEPT
|
||||
: wd(other.wd)
|
||||
, i(other.i)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Assignment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::weekday_indexed& operator =(const etl::chrono::weekday_indexed& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
wd = rhs.wd;
|
||||
i = rhs.i;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Get weekday
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT
|
||||
{
|
||||
return wd;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Get index
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR unsigned index() const ETL_NOEXCEPT
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the weekday and index are valid
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return wd.ok() && (i >= 1U) && (i <= 5);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
etl::chrono::weekday wd;
|
||||
unsigned i;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday_indexed& wd1, const etl::chrono::weekday_indexed& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.weekday() == wd2.weekday()) &&
|
||||
(wd1.index() == wd2.index());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Inequality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday_indexed& wd1, const etl::chrono::weekday_indexed& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(wd1 == wd2);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// weekday index operator from index
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday_indexed etl::chrono::weekday::operator[](unsigned index) const ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::weekday_indexed(*this, index);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function for etl::chrono::weekday_indexed
|
||||
//*************************************************************************
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
template <>
|
||||
struct hash<etl::chrono::weekday_indexed>
|
||||
{
|
||||
size_t operator()(const etl::chrono::weekday_indexed& wdi) const
|
||||
{
|
||||
return etl::hash<etl::chrono::weekday>()(wdi.weekday()) ^ etl::hash<unsigned>()(wdi.index());
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
138
include/etl/private/chrono/weekday_last.h
Normal file
138
include/etl/private/chrono/weekday_last.h
Normal file
@ -0,0 +1,138 @@
|
||||
///\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_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace chrono
|
||||
{
|
||||
//***********************************************************************
|
||||
/// weekday_last
|
||||
//***********************************************************************
|
||||
class weekday_last
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************************************************
|
||||
/// Default constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday_last() ETL_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Construct from unsigned
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday_last(const etl::chrono::weekday& wd_) ETL_NOEXCEPT
|
||||
: wd(wd_)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Copy constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR weekday_last(const etl::chrono::weekday_last& other) ETL_NOEXCEPT
|
||||
: wd(other.wd)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Assignment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::weekday_last& operator =(const etl::chrono::weekday_last& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
wd = rhs.wd;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Get weekday
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT
|
||||
{
|
||||
return wd;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the weekday is valid
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return wd.ok();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
etl::chrono::weekday wd;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday_last& wd1, const etl::chrono::weekday_last& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return (wd1.weekday() == wd2.weekday());
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Inequality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday_last& wd1, const etl::chrono::weekday_last& wd2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(wd1 == wd2);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// weekday index operator from index
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::weekday_last etl::chrono::weekday::operator[](etl::chrono::last_spec) const ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::weekday_last(*this);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function for etl::chrono::weekday_last
|
||||
//*************************************************************************
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
template <>
|
||||
struct hash<etl::chrono::weekday_last>
|
||||
{
|
||||
size_t operator()(const etl::chrono::weekday_last& wdl) const
|
||||
{
|
||||
return etl::hash<etl::chrono::weekday>()(wdl.weekday());
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
@ -28,15 +28,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_YEAR_INCLUDED
|
||||
#define ETL_CHRONO_YEAR_INCLUDED
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../hash.h"
|
||||
|
||||
#include "duration.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef ETL_IN_CHRONO_H
|
||||
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
|
||||
#endif
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -52,7 +46,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Default constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR year()
|
||||
ETL_CONSTEXPR year() ETL_NOEXCEPT
|
||||
: value(0)
|
||||
{
|
||||
}
|
||||
@ -60,7 +54,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Construct from unsigned
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR explicit year(unsigned value_)
|
||||
ETL_CONSTEXPR explicit year(unsigned value_) ETL_NOEXCEPT
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
@ -68,7 +62,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Copy constructor
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR year(const etl::chrono::year& other)
|
||||
ETL_CONSTEXPR year(const etl::chrono::year& other) ETL_NOEXCEPT
|
||||
: value(other.value)
|
||||
{
|
||||
}
|
||||
@ -76,7 +70,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Assignment operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::year& operator =(const etl::chrono::year& rhs)
|
||||
ETL_CONSTEXPR etl::chrono::year& operator =(const etl::chrono::year& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
value = rhs.value;
|
||||
|
||||
@ -148,7 +142,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the year is within the valid -32767 to 32767 range
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return (value >= -32767) && (value <= 32767);
|
||||
}
|
||||
@ -172,7 +166,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Returns <b>true</b> if the year is a leap year
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT
|
||||
{
|
||||
return ((value % 4) == 0) && !((value % 400) == 0);
|
||||
}
|
||||
@ -193,7 +187,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Equality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(y1) == static_cast<unsigned>(y2));
|
||||
}
|
||||
@ -201,7 +195,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Inequality operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(y1 == y2);
|
||||
}
|
||||
@ -209,7 +203,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Less-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(y1) < static_cast<unsigned>(y2));
|
||||
}
|
||||
@ -217,7 +211,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Less-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(y1) <= static_cast<unsigned>(y2));
|
||||
}
|
||||
@ -225,7 +219,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(y1) > static_cast<unsigned>(y2));
|
||||
}
|
||||
@ -233,7 +227,7 @@ namespace etl
|
||||
//***********************************************************************
|
||||
/// Greater-than-or-equal operator
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(y1) >= static_cast<unsigned>(y2));
|
||||
}
|
||||
@ -242,7 +236,7 @@ namespace etl
|
||||
/// Spaceship operator
|
||||
//***********************************************************************
|
||||
#if ETL_USING_CPP20
|
||||
constexpr auto operator <=>(const etl::chrono::year& y1, const etl::chrono::year& y2) noexcept
|
||||
[[nodiscard]] constexpr auto operator <=>(const etl::chrono::year& y1, const etl::chrono::year& y2) noexcept
|
||||
{
|
||||
return (static_cast<unsigned>(y1) <=> static_cast<unsigned>(y2));
|
||||
}
|
||||
@ -252,7 +246,7 @@ namespace etl
|
||||
/// 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_NODISCARD ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
@ -265,7 +259,7 @@ namespace etl
|
||||
/// 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_NODISCARD ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
@ -278,7 +272,7 @@ namespace etl
|
||||
/// 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_NODISCARD ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::year result(y);
|
||||
|
||||
@ -291,7 +285,7 @@ namespace etl
|
||||
/// 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
|
||||
ETL_NODISCARD 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)));
|
||||
@ -336,5 +330,3 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -3003,8 +3003,11 @@
|
||||
<ClInclude Include="..\..\include\etl\private\bitset_new.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\day.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\duration.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\last_spec.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\month.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday_indexed.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday_last.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" />
|
||||
|
||||
@ -1386,6 +1386,15 @@
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday_indexed.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday_last.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\last_spec.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test_string_char.cpp">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user