title | description | ms.date | f1_keywords | helpviewer_keywords | dev_langs | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
year_month_weekday class |
Learn more about: year_month_weekday class |
06/30/2021 |
|
|
|
Represents a specific year, month, and nth weekday of the month.
class year_month_weekday; // C++20
year_month_weekday
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
is a trivially copyable and standard-layout class type.
Name | Description |
---|---|
Constructor |
Construct a year_month_weekday with the specified month and weekday. |
index |
Get the index of the weekday. |
month |
Get the month value. |
ok |
Check if the year_month_weekday 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 as local_days . |
operator sys_days |
Get the count of days from the system_clock epoch to this year_month_weekday as sys_days . |
weekday |
Get the weekday. |
weekday_indexed |
Get the [weekday_indexed ] stored in this year_month_weekday . |
year |
Get the year. |
Name | Description |
---|---|
operator+ |
Add months or years. |
operator- |
Subtract months or years. |
operator== |
Determine whether two year_month_weekday values are equal. |
operator<< |
Output a year_month_weekday to the given stream. |
Header: <chrono>
(since C++20)
Namespace: std::chrono
Compiler Option: /std:c++latest
Constructs a year_month_weekday
.
// 1)
year_month_weekday() = default
// 2)
constexpr year_month_weekday(const year& y, const month& m, const weekday_indexed& wdi) noexcept;
// 3)
constexpr explicit year_month_weekday(const local_days& dp) noexcept;
// 4)
constexpr year_month_weekday(const sys_days& dp) noexcept;
m
The month
value.
dp
A sys_days
or local_days
wdi
The weekday
value.
y
The year
value.
1) The default constructor doesn't initialize any of the fields.
2) Constructs a year_month_weekday
that corresponds to the specified year
, month
, and weekday_indexed
.
3) Constructs a year_month_weekday
that corresponds to the date represented by sys_days{dp.time_since_epoch()}
.
4) Constructs a year_month_weekday
that corresponds to the date represented by dp
. For any year_month_weekday
(ymdl) for which ok()
is true
, comparison with operator==
to year_month_weekday{sys_days{ymdl}}
will be true
.
For information about C++20 syntax used to specify dates, see operator/
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
year_month_weekday ymw{1997y / January / Wednesday[1]};
std::cout << ymw << '\n';
return 0;
}
1997/Jan/Wed[1]
Get the week index of the weekday in this year_month_weekday
.
constexpr unsigned index() const noexcept;
The index of the weekday. For example, if the weekday was the first Wednesday of the week, the index would be 1.
Get the month value.
constexpr month month() const noexcept;
The month
value.
Check if the value stored in this year_month_weekday
is valid. The year
, month
, and weekday_index
stored in this year_month_weekday
must all be ok
for this function to return true
. Otherwise, returns false
.
constexpr bool ok() const noexcept;
true
if the year_month_weekday
value is valid. Otherwise, false
.
A year_month_weekday
is valid if both the month
is valid and the weekday_indexed
value is valid.
Add months or years to this year_month_weekday
.
1) constexpr year_month_weekday& operator+=(const months& m) noexcept;
2) constexpr year_month_weekday& operator+=(const years& y) noexcept;
m
The number of months to add.
y
The number of years to add.
*this
which reflects the result of the addition.
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
year_month_weekday ymw{1997y / January / Wednesday[1]};
std::cout << ymw << '\n';
ymw += months{1};
ymw += years{1};
std::cout << ymw << '\n';
return 0;
}
1997/Jan/Wed[1]
1998/Feb/Wed[1]
Subtract months or years from this year_month_weekday
.
1) constexpr year_month_weekday& operator-=(const months& m) noexcept;
2) constexpr year_month_weekday& operator-=(const years& y) noexcept;
m
The number of months to subtract.
y
The number of years to subtract.
*this
which reflects the result of the subtraction.
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
year_month_weekday ymw{1997y / January / Wednesday[1]};
std::cout << ymw << '\n';
ymw -= months{1};
ymw -= years{1};
std::cout << ymw << '\n';
return 0;
}
1997/Jan/Wed[1]
1995/Dec/Wed[1]
Get the count of days from the system_clock
epoch (1/1/1970) to this year_month_weekday
as local_days
constexpr explicit operator local_days() const noexcept;
If ok()
, returns a count of days as local_days{sys_days{*this}.time_since_epoch()}
. Otherwise the returned value is unspecified.
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;
If ok()
, returns a sys_days
that represents the date that is (index() - 1) * 7
days after the first weekday()
of year()/month()
. If index()
is 0
, the returned sys_days
represents the date 7 days before the first weekday()
of year()/month()
.
Get the weekday
stored in the weekday_indexed
stored in this year_month_weekday
.
constexpr weekday weekday() const noexcept;
The weekday
value.
Get the weekday_indexed
stored in this year_month_weekday
.
constexpr weekday_indexed weekday_indexed() const noexcept;
The weekday_indexed
value.
Get the year value.
constexpr year year() const noexcept;
The year
value.
<chrono>
year
year_month
year_month_day
year_month_day_last
year_month_weekday_last
operator/
Header Files Reference