etl/docs/chrono/year/year_month.md
John Wellbelove 09af946a8f Added more documentation for chrono classes
Updated callouts
2026-04-13 10:59:19 +02:00

3.9 KiB

title
year_month

{{< callout type="info">}} Header: chrono.h
Since: 20.41.0
Similar to: std::chrono::year_month {{< /callout >}}

A template representing a year and month.

class year_month

Construction

ETL_CONSTEXPR 
year_month()

Description
Default constructor.


ETL_CONSTEXPR14 
year_month(const etl::chrono::year&  y, 
           const etl::chrono::month& m) 
ETL_NOEXCEPT

Description
Construct from month and day.

Access

ETL_NODISCARD
ETL_CONSTEXPR14 
etl::chrono::year year() const 
ETL_NOEXCEPT

Return
The year.


ETL_NODISCARD
ETL_CONSTEXPR14 
etl::chrono::month month() const 
ETL_NOEXCEPT

Return
The month.

Tests

ETL_NODISCARD
ETL_CONSTEXPR14 
bool ok() const 
ETL_NOEXCEPT

Return
true if the year and month is within the valid limits.


ETL_NODISCARD
ETL_CONSTEXPR14 
int compare(const etl::chrono::year_month& other) const 
ETL_NOEXCEPT

Description
If y < other.y return -1 If y > other.y return 1 If m < other.m return -1 If m > other.m return 1 Else return 0

Non-member mathematical operators

ETL_CONSTEXPR14
etl::chrono::year_month operator +(const etl::chrono::year_month& ym,
                                   const etl::chrono::years&      dy)

Description
Adds etl::chrono::years.


ETL_CONSTEXPR14
etl::chrono::year_month operator +(const etl::chrono::years&      dy,
                                   const etl::chrono::year_month& ym) 
ETL_NOEXCEPT

Description
Adds etl::chrono::years.


ETL_CONSTEXPR14
etl::chrono::year_month operator +(const etl::chrono::year_month& ym,
                                   const etl::chrono::months&     dm) 
ETL_NOEXCEPT

Description
Adds etl::chrono::months.


ETL_CONSTEXPR14 
etl::chrono::year_month operator +(const etl::chrono::months& dm,
                                   const etl::chrono::year_month& ym) 
ETL_NOEXCEPT

Description
Adds etl::chrono::months.


ETL_CONSTEXPR14 
etl::chrono::year_month operator -(const etl::chrono::year_month& ym,
                                   const etl::chrono::years&      dy) 
ETL_NOEXCEPT

Description
Subtracts etl::chrono::years.


ETL_CONSTEXPR14 
etl::chrono::year_month operator -(const etl::chrono::year_month& ym,
                                   const etl::chrono::months&     dm) 
ETL_NOEXCEPT

Description
Subtracts etl::chrono::months.


ETL_CONSTEXPR14 
etl::chrono::months operator -(const etl::chrono::year_month& ym1,
                               const etl::chrono::year_month& ym2) 
ETL_NOEXCEPT

Description
Subtracts etl::chrono::year_month.

Non-member comparison operators

ETL_CONSTEXPR14 
bool operator ==(const etl::chrono::year_month& lhs, 
                 const etl::chrono::year_month& rhs) 
ETL_NOEXCEPT

Description
Equality operator.


ETL_CONSTEXPR14
bool operator !=(const etl::chrono::year_month& lhs, 
                 const etl::chrono::year_month& rhs) 
ETL_NOEXCEPT

Description
Inequality operator.


[[nodiscard]] friend constexpr
auto operator <=>(const etl::chrono::year_month& lhs, 
                  const etl::chrono::year_month& rhs)
ETL_NOEXCEPT

Description
Spaceship operator
C++20


ETL_CONSTEXPR14 
int compare(const year_month& other) const 
ETL_NOEXCEPT

Description
Compare year_month with another. if month < other.month, returns -1 else if month > other.month, returns 1 else if day < other.day, returns -1 else if day > other.day, returns 1 else returns 0;

Hash

template <typename TRep, typename TPeriod> struct hashetl::chrono::year_month Description
Hash function for etl::chrono::year_month.