次の方法で共有


year_month_weekday クラス

月の特定の年、月、および n 番目の曜日を表します。

構文

class year_month_weekday; // C++20

解説

year_month_weekday では、年と月指向の算術演算がサポートされますが、日指向の算術演算はサポートされません。 日指向の算術演算の場合は、日指向の算術演算をサポートする sys_days 変換を使用して、sys_days に変換します。

year_month_weekday は、普通のコピー可能な、標準レイアウト クラス型です。

メンバー

名前 説明
Constructor 指定した月と曜日を使用して year_month_weekday を構成します。
index 曜日のインデックスを取得します。
month 月の値を取得します。
ok year_month_weekday が有効かどうかを確認します。
operator+= 指定した月数または年数を加算します。
operator-= 指定した月数または年数を減算します。
operator local_days system_clock エポックからこの year_month_weekday への日数を local_days として取得します。
operator sys_days system_clock エポックからこの year_month_weekday への日数を sys_days として取得します。
weekday 曜日を取得します。
weekday_indexed この year_month_weekday に格納されている [weekday_indexed] を取得します。
year 年を取得します。

非メンバー

名前 説明
operator+ 月または年を加算します。
operator- 月または年を減算します。
operator== 2 つの year_month_weekday 値が等しいかどうかを判断します。
operator<< 指定したストリームに year_month_weekday を出力します。

要件

ヘッダー:<chrono> (C++20 以降)

名前空間std::chrono:

コンパイラ オプション:/std:c++latest

Constructor

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
month の値です。

dp
sys_days または local_days

wdi
weekday の値です。

y
year の値です。

解説: コンストラクター

1) 既定のコンストラクターは、いずれのフィールドも初期化しません。

2) 指定された yearmonth、および weekday_indexed に対応する year_month_weekday を構築します。

3) sys_days{dp.time_since_epoch()} によって表現される日付に対応する year_month_weekday を構築します。

4) dp によって表現される日付に対応する year_month_weekday を構築します。 ok()true であるすべての year_month_weekday (ymdl) について、operator==year_month_weekday{sys_days{ymdl}} の比較は true になります。

日付の指定に使用される C++20 構文の詳細については、以下を参照してください。 operator/

例: year_month_weekday を作成する

// 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]

index

この year_month_weekday で曜日のインデックスを取得します。

constexpr unsigned index() const noexcept;

戻り値

曜日のインデックス。 たとえば、曜日が週の最初の水曜日の場合、インデックスは 1 になります。

month

月の値を取得します。

constexpr month month() const noexcept;

戻り値

month の値です。

ok

この year_month_weekday に格納されている値が有効かどうかを確認します。 この関数が true を返すには、この year_month_weekday に格納されている yearmonthweekday_index はすべて ok である必要があります。 それ以外の場合、false を返します。

constexpr bool ok() const noexcept;

戻り値

year_month_weekday 値が有効な場合は true。 それ以外の場合は false
month が有効で、weekday_indexed 値が有効な場合、year_month_weekday は有効です。

operator+=

この year_month_weekday に月または年を追加します。

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

パラメーター

m
加算する月数。

y
加算する年数。

戻り値

加算の結果を反映する *this

例: 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';

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

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

operator-=

この year_month_weekday から月または年を減算します。

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

パラメーター

m
減算する月数。

y
減算する年数。

戻り値

減算の結果を反映する *this

例: 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';

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

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

operator local_days

system_clock エポック (1/1/1970) からこの year_month_weekday への日数を local_days として取得します

constexpr explicit operator local_days() const noexcept;

戻り値

ok() の場合、日数を local_days{sys_days{*this}.time_since_epoch()} として返します。 それ以外の場合、返される値は指定されません。

operator sys_days

system_clock エポック (1/1/1970) からこの year_month_day への日数を sys_days として取得します。

constexpr operator sys_days() const noexcept;

戻り値

ok() の場合、year()/month() の最初の weekday() から (index() - 1) * 7 日後の日付を表す sys_days を返します。 index()0 の場合、返される sys_days は、year()/month() の最初の weekday() の 7 日前の日付を表します。

weekday

この year_month_weekday に格納されている weekday_indexed に格納されている weekday を取得します。

constexpr weekday weekday() const noexcept;

戻り値

weekday の値です。

weekday_indexed

この year_month_weekday に格納されている weekday_indexed を取得します。

constexpr weekday_indexed weekday_indexed() const noexcept;

戻り値

weekday_indexed の値です。

year

年の値を取得します。

constexpr year year() const noexcept;

戻り値

year の値です。

関連項目

<chrono>
year
year_month
year_month_day
year_month_day_last
year_month_weekday_last
operator/ヘッダー ファイル リファレンス