Szerkesztés

Megosztás a következőn keresztül:


year_month_weekday_last class

A specific year, month, and last weekday of the month.

Syntax

class year_month_weekday_last; // C++20

Remarks

year_month_weekday_last supports years- and months-oriented arithmetic, but not days-oriented arithmetic. For days-oriented arithmetic, use the sys_days conversion to convert to a sys_days, which supports days-oriented arithmetic.

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

Members

Name Description
Constructor Construct a year_month_weekday_last with the specified month and weekday.
month Get the month value.
ok Check if the year_month_weekday_last is valid.
operator+= Add the specified number of months or years.
operator-= Subtract the specified number of months or years.
operator local_days Get the count of days from the system_clock epoch to this year_month_weekday_last as local_days.
operator sys_days Get the count of days from the system_clock epoch to this year_month_weekday_last as sys_days.
weekday Get the weekday.
weekday_last Get the weekday_last stored in this year_month_weekday_last.
year Get the year.

Non-members

Name Description
operator+ Add months or years.
operator- Subtract months or years.
operator== Determine whether two year_month_weekday_last values are equal.
operator<< Output a year_month_weekday_last to the given stream.

Requirements

Header: <chrono> (since C++20)

Namespace: std::chrono

Compiler Option: /std:c++latest

Constructor

Constructs a year_month_weekday_last.

constexpr year_month_weekday_last(const year& y, const month& m, const weekday_last& wdl) noexcept

Parameters

m
The month value.

wdl
The weekday_last value.

y
The year value.

For information about C++20 syntax used to specify dates, see operator/

Example: Create a year_month_weekday_last

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    year_month_weekday_last ymwl{ 1997y / January / Wednesday[last] };
    std::cout << ymwl << '\n';
    
    return 0;
}
1997/Jan/Wed[last]

month

Get the month value.

constexpr month month() const noexcept;

Return value

The month value.

ok

Check if the value stored in this year_month_weekday_last is valid. The year, month, and weekday_last stored in this year_month_weekday_last must all be ok for this function to return true. Otherwise, returns false.

constexpr bool ok() const noexcept;

Return value

true if the year_month_weekday_last value is valid. Otherwise, false.
A year_month_weekday_last is valid if the month, weekday_indexed, and year are all valid.

operator+=

Add months or years to this year_month_weekday_last.

1) constexpr year_month_weekday_last& operator+=(const months& m) noexcept;
2) constexpr year_month_weekday_last& operator+=(const years& y) noexcept;

Parameters

m
The number of months to add.

y
The number of years to add.

Return value

*this which reflects the result of the addition.

Example: operator+=

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    year_month_weekday_last ymwl{ year(1997) / January / Wednesday[last] };
    std::cout << ymwl << '\n';

    ymwl += months{ 1 };
    ymwl += years{ 1 };

    std::cout << ymwl << '\n';
    
    return 0;
}
1997/Jan/Wed[last]
1998/Feb/Wed[last]

operator-=

Subtract months or years from this year_month_weekday_last.

1) constexpr year_month_weekday_last& operator-=(const months& m) noexcept;
2) constexpr year_month_weekday_last& operator-=(const years& y) noexcept;

Parameters

m
The number of months to subtract.

y
The number of years to subtract.

Return value

*this which reflects the result of the subtraction.

Example: operator-=

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    year_month_weekday_last ymwl{ year(1997) / January / Wednesday[last] };
    std::cout << ymwl << '\n';

    ymwl -= months{ 1 };
    ymwl -= years{ 1 };

    std::cout << ymwl << '\n';
    
    return 0;
}
1997/Jan/Wed[last]
1995/Dec/Wed[last]

operator local_days

Get the count of days from the system_clock epoch (1/1/1970) to this year_month_weekday_last as local_days

constexpr explicit operator local_days() const noexcept;

Return value

If ok(), returns a count of days as local_days{sys_days{*this}.time_since_epoch()}. Otherwise the returned value is unspecified.

operator sys_days

Get the count of days from the system_clock epoch (1/1/1970) to this year_month_day as sys_days.

constexpr operator sys_days() const noexcept;

Return value

If ok() == true, returns a sys_days that represents the last weekday() of year() / month() (note: the / is the date operator, not a division). Otherwise the returned value is unspecified.

weekday

Get the weekday.

constexpr weekday weekday() const noexcept;

Return value

The weekday.

weekday_last

Get the weekday_last stored in this year_month_weekday_last.

constexpr weekday_indexed weekday_last() const noexcept;

Return value

The weekday_last.

year

Get the year value.

constexpr year year() const noexcept;

Return value

The year value.

See also

<chrono>
year
year_month
year_month_day
year_month_day_last
year_month_weekday
operator/
Header Files Reference