Namespaces
Variants

std::chrono::year_month_weekday_last:: ok

From cppreference.net
constexpr bool ok ( ) const noexcept ;
(自 C++20 起)

检查此对象是否表示一个有效日期。由于 year_month_weekday_last 表示特定月份的最后一周工作日,只要年份、月份和工作日有效,该对象即为有效。

返回值

year ( ) . ok ( ) && month ( ) . ok ( ) && weekday ( ) . ok ( )

示例

#include <cassert>
#include <chrono>
using namespace std::chrono;
int main()
{
    auto ymwdl{Tuesday[last]/11/2020};
    assert(ymwdl.ok());
    ymwdl = Tuesday[last]/-2/2021;
    assert(!ymwdl.ok());
    ymwdl += months(0); // 标准化月份
    assert(ymwdl.ok());
}