etl/docs/chrono/year/year.md
2026-05-19 12:12:14 +01:00

5.5 KiB

title
year

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

A class representing a year.

class year

Member types

rep The internal representation.

Construction

ETL_CONSTEXPR 
year()
ETL_NOEXCEPT

Description
Default constructor.


ETL_CONSTEXPR 
explicit year(unsigned value) 
ETL_NOEXCEPT

Description
Construct from unsigned.


ETL_CONSTEXPR14 
year(const etl::chrono::year& other) 
ETL_NOEXCEPT

Description
Copy constructor.

Tests

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

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

Assignment

ETL_CONSTEXPR14 
etl::chrono::year& operator =(const etl::chrono::year& rhs) 
ETL_NOEXCEPT

Description
Assignment operator

Increment / decrement

ETL_CONSTEXPR14 
etl::chrono::year& operator ++() 
ETL_NOEXCEPT

Description
Pre-increment operator.


ETL_CONSTEXPR14
etl::chrono::year operator ++(int) 
ETL_NOEXCEPT

Description
Post-increment operator.


ETL_CONSTEXPR14
etl::chrono::year& operator --() 
ETL_NOEXCEPT

Description
Pre-decrement operator.


ETL_CONSTEXPR14 
etl::chrono::year operator --(int) 
ETL_NOEXCEPT

Description
Post-decrement operator.

Mathematical operators

ETL_CONSTEXPR14 
etl::chrono::year& operator +=(const etl::chrono::years& ys) 
ETL_NOEXCEPT

Description
Plus-equals operator adding etl::chrono::years.


ETL_CONSTEXPR14 
etl::chrono::year& operator -=(const etl::chrono::years& ys) 
ETL_NOEXCEPT

Description
Minus-equals operator subtracting etl::chrono::years.

Tests

ETL_NODISCARD
ETL_CONSTEXPR14 
bool ok() const 
ETL_NOEXCEPT

Description
Returns true if the year is within the valid -32767 to 32767 range.


ETL_NODISCARD
ETL_CONSTEXPR14 
bool is_leap() const 
ETL_NOEXCEPT

Description
Returns true if the year is a leap year.

Constants

ETL_NODISCARD
static 
ETL_CONSTEXPR14
etl::chrono::year min()
ETL_NOEXCEPT

Description
The minimum year value for which ok() will return true.


ETL_NODISCARD
static 
ETL_CONSTEXPR14 
etl::chrono::year max()
ETL_NOEXCEPT

Description
The maximum year value for which ok() will return true.

Conversion

ETL_CONSTEXPR14 
operator int() const 
ETL_NOEXCEPT

Description
Conversion operator to unsigned int.

Non-member mathematical operators

ETL_CONSTEXPR14 
etl::chrono::year operator +(const etl::chrono::year& y, 
                             const etl::chrono::years& ys) 
ETL_NOEXCEPT

Description
Add etl::chrono::years to etl::chrono::year. Return
etl::chrono::year.


ETL_CONSTEXPR14 
etl::chrono::year operator +(const etl::chrono::years& ys, 
                             const etl::chrono::year& y) 
ETL_NOEXCEPT

Description
Add etl::chrono::year to etl::chrono::years. Return
etl::chrono::year.


ETL_CONSTEXPR14 
etl::chrono::year operator -(const etl::chrono::year& y, 
                             const etl::chrono::years& ys) 
ETL_NOEXCEPT

Description
Subtract etl::chrono::years from etl::chrono::year. Return
etl::chrono::year.


ETL_CONSTEXPR14
etl::chrono::year operator -(const etl::chrono::years& ys, 
                             const etl::chrono::year& y) 
ETL_NOEXCEPT

Description
Subtract etl::chrono::year from etl::chrono::years. Return
etl::chrono::years.


ETL_CONSTEXPR14 
etl::chrono::years operator -(const etl::chrono::year& y1, 
                              const etl::chrono::year& y2) ETL_NOEXCEPT

Description
Subtract etl::chrono::year from etl::chrono::year. Return
etl::chrono::years.

Non-member comparison operators

ETL_CONSTEXPR14 
bool operator ==(const etl::chrono::year& y1, 
                 const etl::chrono::year& y2)
ETL_NOEXCEPT

Description
Equality operator.


ETL_CONSTEXPR14 
bool operator !=(const etl::chrono::year& y1, 
                 const etl::chrono::year& y2) 
ETL_NOEXCEPT

Description
Inequality operator.


ETL_CONSTEXPR14 
bool operator <(const etl::chrono::year& y1, 
                const etl::chrono::year& y2) 
ETL_NOEXCEPT

Description
Less-than operator.


ETL_CONSTEXPR14 
bool operator <=(const etl::chrono::year& y1, 
                 const etl::chrono::year& y2) 
ETL_NOEXCEPT

Description
Less-than-or-equal operator.


ETL_CONSTEXPR14 
bool operator >(const etl::chrono::year& y1, 
                const etl::chrono::year& y2) 
ETL_NOEXCEPT

Description
Greater-than operator.


ETL_CONSTEXPR14
bool operator >=(const etl::chrono::year& y1, 
                 const etl::chrono::year& y2) 
ETL_NOEXCEPT

Description
Greater-than-or-equal operator.


[[nodiscard]] inline constexpr 
auto operator <=>(const etl::chrono::year& y1, 
                  const etl::chrono::year& y2) 
noexcept

Description
Spaceship operator.
C++20

Hash

template <typename TRep, typename TPeriod>
struct hash<etl::chrono::year>

Description
Hash function for etl::chrono::year.