std::chrono...st::weekday(3)

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

okay bestie, welcome to the std::chrono...st::weekday(3) page from the C++ Standard Libary πŸ’– this one is short and sweet, and it’s literally all about grabbing the weekday back out of a std::chrono::weekday_last. no cap.

πŸŽ€ NAME πŸŽ€

std::chrono::weekday_last::weekday - std::chrono::weekday_last::weekday

πŸ¦‹ Synopsis πŸ¦‹

here’s the signature, bestie β€” and yes, it’s been around since C++20 ✨:

constexpr std::chrono::weekday weekday() const noexcept;

Retrieves a copy of the std::chrono::weekday object stored in *this. like, it just hands you back the weekday that’s sitting inside. periodt.

πŸ’– Return value πŸ’–

A copy of the std::chrono::weekday object stored in *this. that’s the whole vibe β€” just a copy of the weekday object 🫢

✨ Example ✨

okay so this example is doing the absolute most in the cutest way: it makes a weekday_last for the last Tuesday of a month, checks a date, then changes the weekday and checks again. slay.

// Run this code

#include <chrono>
#include <iostream>
using namespace std::chrono;

int main()
{
    std::cout << std::boolalpha;

    auto wdl{Tuesday[last]}; // Last Tuesday of a month
    std::cout << (year_month_day{wdl/10/2019} ==
                  year_month_day{October/29/2019}) << ' ';

    wdl = {(wdl.weekday() + days(2))[last]}; // Last Tuesday is now last Thursday
    std::cout << (year_month_day{wdl/10/2019} ==
                  year_month_day{October/31/2019}) << '\n';
}

🌈 Output: 🌈

true true

xoxo, your C++ bestie πŸ’… β€” source: http://cppreference.com, dated 2024.06.10 πŸŽ€βœ¨

πŸ“¦ where this page comes from