Files
2025-10-25 03:02:53 +03:00

13 KiB

[time.cal.ymdlast]

30 Time library [time]

30.8 The civil calendar [time.cal]

30.8.15 Class year_month_day_last [time.cal.ymdlast]

30.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 onlypublic: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; };}

1

#

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 1:

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 28) and Cpp17LessThanComparable (Table 29) requirements.

2

#

year_month_day_last is a trivially copyable and standard-layout class type.

30.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;

1

#

Effects: Initializes y_ with y and mdl_ with mdl.

🔗

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

2

#

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 tomonths ([over.ics.rank]).

3

#

Effects: *this = *this + m.

4

#

Returns: *this.

🔗

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

5

#

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 tomonths ([over.ics.rank]).

6

#

Effects: *this = *this - m.

7

#

Returns: *this.

🔗

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

8

#

Effects: *this = *this + y.

9

#

Returns: *this.

🔗

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

10

#

Effects: *this = *this - y.

11

#

Returns: *this.

🔗

constexpr chrono::year year() const noexcept;

12

#

Returns: y_.

🔗

constexpr chrono::month month() const noexcept;

13

#

Returns: mdl_.month().

🔗

constexpr chrono::month_day_last month_day_last() const noexcept;

14

#

Returns: mdl_.

🔗

constexpr chrono::day day() const noexcept;

15

#

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.

16

#

[Note 1:

This value might be computed on demand.

— end note]

🔗

constexpr operator sys_days() const noexcept;

17

#

Returns: sys_days{year()/month()/day()}.

🔗

constexpr explicit operator local_days() const noexcept;

18

#

Returns: local_days{sys_days{*this}.time_since_epoch()}.

🔗

constexpr bool ok() const noexcept;

19

#

Returns: y_.ok() && mdl_.ok().

30.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;

1

#

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;

2

#

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;

3

#

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 tomonths ([over.ics.rank]).

4

#

Returns: (ymdl.year() / ymdl.month() + dm) / last.

🔗

constexpr year_month_day_last operator+(const months& dm, const year_month_day_last& ymdl) noexcept;

5

#

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 tomonths ([over.ics.rank]).

6

#

Returns: ymdl + dm.

🔗

constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const months& dm) noexcept;

7

#

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 tomonths ([over.ics.rank]).

8

#

Returns: ymdl + (-dm).

🔗

constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const years& dy) noexcept;

9

#

Returns: {ymdl.year()+dy, ymdl.month_day_last()}.

🔗

constexpr year_month_day_last operator+(const years& dy, const year_month_day_last& ymdl) noexcept;

10

#

Returns: ymdl + dy.

🔗

constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const years& dy) noexcept;

11

#

Returns: ymdl + (-dy).

🔗

template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month_day_last& ymdl);

12

#

Effects: Equivalent to:return os << format(os.getloc(), STATICALLY-WIDEN("{}/{:L}"), ymdl.year(), ymdl.month_day_last());