Loading...
Searching...
No Matches
day.h
Go to the documentation of this 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
{
//***********************************************************************
//***********************************************************************
class day
{
public:
using rep = uint_least8_t;
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR day() ETL_NOEXCEPT
: value(0)
{
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR explicit day(unsigned value_) ETL_NOEXCEPT
: value(static_cast<rep>(value_))
{
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR14 etl::chrono::day& operator++() ETL_NOEXCEPT
{
++value;
return *this;
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR14 etl::chrono::day operator++(int) ETL_NOEXCEPT
{
etl::chrono::day temp = *this;
++value;
return temp;
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR14 etl::chrono::day& operator--() ETL_NOEXCEPT
{
--value;
return *this;
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR14 etl::chrono::day operator--(int) ETL_NOEXCEPT
{
etl::chrono::day temp = *this;
--value;
return temp;
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR14 etl::chrono::day& operator+=(const etl::chrono::days& ds) ETL_NOEXCEPT
{
value += static_cast<rep>(ds.count());
return *this;
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR14 etl::chrono::day& operator-=(const etl::chrono::days& ds) ETL_NOEXCEPT
{
value -= static_cast<rep>(ds.count());
return *this;
}
//***********************************************************************
//***********************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
{
return (value >= 1U) && (value <= 31U);
}
//***********************************************************************
//***********************************************************************
ETL_CONSTEXPR14 /*explicit*/ operator unsigned() const ETL_NOEXCEPT
{
return value;
}
//***********************************************************************
//***********************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 int compare(const day& other) const ETL_NOEXCEPT
{
if (value < other.value)
return -1;
if (value > other.value)
return 1;
return 0;
}
private:
rep value;
};
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 bool operator==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) == static_cast<unsigned>(d2));
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 bool operator!=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return !(d1 == d2);
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 bool operator<(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) < static_cast<unsigned>(d2));
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 bool operator<=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) <= static_cast<unsigned>(d2));
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 bool operator>(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) > static_cast<unsigned>(d2));
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 bool operator>=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) >= static_cast<unsigned>(d2));
}
//***********************************************************************
//***********************************************************************
#if ETL_USING_CPP20
[[nodiscard]]
inline constexpr auto operator<=>(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
}
#endif
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 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;
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 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;
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 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;
}
//***********************************************************************
//***********************************************************************
inline ETL_CONSTEXPR14 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)));
}
} // namespace chrono
//*************************************************************************
//*************************************************************************
#if ETL_USING_8BIT_TYPES
template <>
struct hash<etl::chrono::day>
{
size_t operator()(const etl::chrono::day& d) const
{
etl::chrono::day::rep value = static_cast<etl::chrono::day::rep>(static_cast<unsigned>(d));
const uint8_t* p = reinterpret_cast<const uint8_t*>(&value);
return etl::private_hash::generic_hash<size_t>(p, p + sizeof(value));
}
};
#endif
} // namespace etl
#if ETL_HAS_CHRONO_LITERALS_DAY
namespace etl
{
inline namespace literals
{
inline namespace chrono_literals
{
#if ETL_USING_VERBOSE_CHRONO_LITERALS
inline ETL_CONSTEXPR14 etl::chrono::day operator""_day(unsigned long long d) ETL_NOEXCEPT
#else
inline ETL_CONSTEXPR14 etl::chrono::day operator""_d(unsigned long long d) ETL_NOEXCEPT
#endif
{
return etl::chrono::day(static_cast<unsigned>(d));
}
} // namespace chrono_literals
} // namespace literals
} // namespace etl
#endif
etl::chrono::day
day
Definition day.h:43
etl::chrono::day::operator+=
ETL_CONSTEXPR14 etl::chrono::day & operator+=(const etl::chrono::days &ds) ETL_NOEXCEPT
Plus-equals operator adding etl::chrono::days.
Definition day.h:109
etl::chrono::day::day
ETL_CONSTEXPR day() ETL_NOEXCEPT
Default constructor.
Definition day.h:51
etl::chrono::day::operator++
ETL_CONSTEXPR14 etl::chrono::day & operator++() ETL_NOEXCEPT
Pre-increment operator.
Definition day.h:67
etl::chrono::day::ok
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the day is within the valid 1 to 31 range.
Definition day.h:129
etl::chrono::day::operator-=
ETL_CONSTEXPR14 etl::chrono::day & operator-=(const etl::chrono::days &ds) ETL_NOEXCEPT
Minus-equals operator subtracting etl::chrono::days.
Definition day.h:119
etl::chrono::day::operator--
ETL_CONSTEXPR14 etl::chrono::day & operator--() ETL_NOEXCEPT
Pre-decrement operator.
Definition day.h:88
etl::chrono::day::compare
ETL_NODISCARD ETL_CONSTEXPR14 int compare(const day &other) const ETL_NOEXCEPT
Definition day.h:148
etl::chrono::day::operator--
ETL_CONSTEXPR14 etl::chrono::day operator--(int) ETL_NOEXCEPT
Post-decrement operator.
Definition day.h:98
etl::chrono::day::day
ETL_CONSTEXPR day(unsigned value_) ETL_NOEXCEPT
Construct from unsigned.
Definition day.h:59
etl::chrono::day::operator++
ETL_CONSTEXPR14 etl::chrono::day operator++(int) ETL_NOEXCEPT
Post-increment operator.
Definition day.h:77
etl::chrono::operator+
ETL_CONSTEXPR14 etl::chrono::day operator+(const etl::chrono::day &d, const etl::chrono::days &ds) ETL_NOEXCEPT
Spaceship operator.
Definition day.h:226
etl::chrono::operator-
ETL_CONSTEXPR14 etl::chrono::day operator-(const etl::chrono::day &d, const etl::chrono::days &ds) ETL_NOEXCEPT
Definition day.h:252
etl::chrono::operator<
ETL_CONSTEXPR14 bool operator<(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Less-than operator.
Definition day.h:182
etl::chrono::operator>=
ETL_CONSTEXPR14 bool operator>=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Greater-than-or-equal operator.
Definition day.h:206
etl::chrono::operator==
ETL_CONSTEXPR14 bool operator==(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Equality operator.
Definition day.h:166
etl::chrono::operator<=
ETL_CONSTEXPR14 bool operator<=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Less-than-or-equal operator.
Definition day.h:190
etl::chrono::operator!=
ETL_CONSTEXPR14 bool operator!=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Inequality operator.
Definition day.h:174
etl::chrono::operator>
ETL_CONSTEXPR14 bool operator>(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Greater-than operator.
Definition day.h:198
etl
Definition absolute.h:40