std::chrono..._weekday::ok(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

okay so bestie, this is the std::chrono..._weekday::ok(3) page from the C++ Standard Libary (yes, β€œLibary” is literally how it’s spelled in the header β€” iconic typo behavior πŸ’…). The NAME section is out here saying std::chrono::year_month_weekday::ok and then saying std::chrono::year_month_weekday::ok again, so it’s giving β€œsay it twice so it sticks.” We love a consistent queen ✨.


πŸ¦‹ Synopsis πŸ¦‹

constexpr bool ok() const noexcept;  (since C++20)

It checks if this year_month_weekday object represents a valid date. That’s the whole vibe check 🫢.


πŸ’– Return value πŸ’–

It’s true if this year_month_weekday object represents a valid date β€” and by that we mean this whole thing is true:

year().ok() && month().ok() && weekday_indexed().ok()

…AND there are at least index() weekday()s in the specified year and month. Otherwise? false, bestie. No cap 😭.


πŸŽ€ Example πŸŽ€

The source says // Run this code, so go off:

#include <cassert>
#include <chrono>

int main()
{
    auto ymwdi{std::chrono::Wednesday[1]/1/2021};
    assert(ymwdi.ok());
    ymwdi =
std::chrono::year(2021)/std::chrono::month(1)/std::chrono::Wednesday[42];
    assert(!ymwdi.ok());
}

Signing off with the footer energy, fr fr: source/version/date is http://cppreference.com, 2024.06.10, and the page tag is std::chrono..._weekday::ok(3). Bye bestie β€” go check your dates πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from