27 Time library [time]

27.8 The civil calendar [time.cal]

27.8.15 Class year_­month_­day_­last [time.cal.ymdlast]

27.8.15.1 Overview [time.cal.ymdlast.overview]

namespace std::chrono {
  class year_month_day_last {
    chrono::year           y_;          // exposition only
    chrono::month_day_last mdl_;        // exposition only

  public:
    constexpr year_month_day_last(const chrono::year& y,
                                  const chrono::month_day_last& mdl) noexcept;

    constexpr year_month_day_last& operator+=(const months& m) noexcept;
    constexpr year_month_day_last& operator-=(const months& m) noexcept;
    constexpr year_month_day_last& operator+=(const years& y)  noexcept;
    constexpr year_month_day_last& operator-=(const years& y)  noexcept;

    constexpr chrono::year           year()           const noexcept;
    constexpr chrono::month          month()          const noexcept;
    constexpr chrono::month_day_last month_day_last() const noexcept;
    constexpr chrono::day            day()            const noexcept;

    constexpr          operator sys_days()   const noexcept;
    constexpr explicit operator local_days() const noexcept;
    constexpr bool ok() const noexcept;
  };
}
year_­month_­day_­last represents the last day of a specific year and month.
year_­month_­day_­last is a field-based time point with a resolution of days, except that it is restricted to pointing to the last day of a year and month.
[Note
:
year_­month_­day_­last supports years- and months-oriented arithmetic, but not days-oriented arithmetic.
For the latter, there is a conversion to sys_­days, which efficiently supports days-oriented arithmetic.
— end note
]
year_­month_­day_­last meets the Cpp17EqualityComparable (Table 25) and Cpp17LessThanComparable (Table 26) requirements.
year_­month_­day_­last is a trivially copyable and standard-layout class type.

27.8.15.2 Member functions [time.cal.ymdlast.members]

constexpr year_month_day_last(const chrono::year& y, const chrono::month_day_last& mdl) noexcept;
Effects: Initializes y_­ with y and mdl_­ with mdl.
constexpr year_month_day_last& operator+=(const months& m) noexcept;
Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to years is worse than its implicit conversion sequence to months ([over.ics.rank]).
Effects: *this = *this + m.
Returns: *this.
constexpr year_month_day_last& operator-=(const months& m) noexcept;
Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to years is worse than its implicit conversion sequence to months ([over.ics.rank]).
Effects: *this = *this - m.
Returns: *this.
constexpr year_month_day_last& operator+=(const years& y) noexcept;
Effects: *this = *this + y.
Returns: *this.
constexpr year_month_day_last& operator-=(const years& y) noexcept;
Effects: *this = *this - y.
Returns: *this.
constexpr chrono::year year() const noexcept;
Returns: y_­.
constexpr chrono::month month() const noexcept;
Returns: mdl_­.month().
constexpr chrono::month_day_last month_day_last() const noexcept;
Returns: mdl_­.
constexpr chrono::day day() const noexcept;
Returns: If ok() is true, returns a day representing the last day of the (year, month) pair represented by *this.
Otherwise, the returned value is unspecified.
[Note
:
This value may be computed on demand.
— end note
]
constexpr operator sys_days() const noexcept;
Returns: sys_­days{year()/month()/day()}.
constexpr explicit operator local_days() const noexcept;
Returns: local_­days{sys_­days{*this}.time_­since_­epoch()}.
constexpr bool ok() const noexcept;
Returns: y_­.ok() && mdl_­.ok().

27.8.15.3 Non-member functions [time.cal.ymdlast.nonmembers]

constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
Returns: x.year() == y.year() && x.month_­day_­last() == y.month_­day_­last().
constexpr strong_ordering operator<=>(const year_month_day_last& x, const year_month_day_last& y) noexcept;
Effects: Equivalent to:
if (auto c = x.year() <=> y.year(); c != 0) return c;
return x.month_day_last() <=> y.month_day_last();
constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to years is worse than its implicit conversion sequence to months ([over.ics.rank]).
Returns: (ymdl.year() / ymdl.month() + dm) / last.
constexpr year_month_day_last operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to years is worse than its implicit conversion sequence to months ([over.ics.rank]).
Returns: ymdl + dm.
constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
Constraints: If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to years is worse than its implicit conversion sequence to months ([over.ics.rank]).
Returns: ymdl + (-dm).
constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
Returns: {ymdl.year()+dy, ymdl.month_­day_­last()}.
constexpr year_month_day_last operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
Returns: ymdl + dy.
constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
Returns: ymdl + (-dy).
template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month_day_last& ymdl);
Effects: Equivalent to:
return os << format(os.getloc(), STATICALLY-WIDEN<charT>("{}/{}"),
                    ymdl.year(), ymdl.month_day_last());