std::chrono...st::weekday(3)
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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms