std::chrono...eekday_last(3)
β¨ std::chrono::year_month_weekday_last β¨
Okay so bestie, let me introduce you to std::chrono::year_month_weekday_last β the C++ Standard Library's way of saying "the last weekday of a specific year and month" and honestly? It's iconic. π
This whole thing lives in the <chrono> header, and it's been serving main character energy since C++20. π
class year_month_weekday_last; (since C++20)
π¦ SYNOPSIS π¦
So picture this: the class year_month_weekday_last represents the last weekday of a specific year and month. That's it. That's the vibe. π
It's a field-based time point with a resolution of std::chrono::days, except β and this is the key part β it's literally locked to the last weekday of a year and month. Like, it can't be anything else. Boundaries, bestie. π
The good news? std::chrono::years- and std::chrono::months-oriented arithmetic are supported directly. No extra steps, no cap. π₯
Also there's an implicit conversion to std::chrono::sys_days that lets you do std::chrono::days-oriented arithmetic efficiently. It's giving seamless integration, fr fr. β¨
And one more thing β year_month_weekday_last is a TriviallyCopyable StandardLayoutType. Which basically means it's the low-maintenance friend who just works. No drama. π«Ά
π MEMBER FUNCTIONS π
Okay so these are the methods it brings to the group chat:
- constructor β constructs a
year_month_weekday_last(public member function) operator+=β modifies the time point by some number of months or yearsoperator-=β (public member function) same energy, but subtractingyearβ accesses the fields of this objectmonthβ literally accessing the month field, (public member function)weekdayβ the weekday field, (public member function)weekday_lastβ the weekday_last field, (public member function)operator sys_daysβ converts to astd::chrono::time_pointoperator local_daysβ (public member function) converts to local daysokβ checks whether this object represents a valid date (public member function). Like a vibe check for your date. π
π NONMEMBER FUNCTIONS π
These are the outside friends who still show up for you:
operator==β compares twoyear_month_weekday_lastvalues (C++20) (function)operator+β adds or subtracts ayear_month_weekday_lastand some number of years or monthsoperator-β (C++20) (function) same thing but the other directionoperator<<β outputs ayear_month_weekday_lastinto a stream (C++20) (function template). Great for when you need to print it and show everyone. π¨οΈβ¨
πΈ HELPER CLASSES πΈ
The support squad that makes everything work behind the scenes:
std::formatter<std::chrono::year_month_weekday_last>β formatting support foryear_month_weekday_last(C++20) (class template specialization). You love to see it. πstd::hash<std::chrono::year_month_weekday_last>β hash support forstd::chrono::year_month_weekday_last(C++26) (class template specialization). Future vibes only. π¦
π Pro tip from your bestie: this class is field-based, meaning it stores year, month, and weekday_last as separate fields β not as a single count since some epoch. That's the whole point and it's lowkey genius.
Okay that's the whole page, bestie. You're now officially caught up on std::chrono::year_month_weekday_last. Go forth and compute the last weekday of any month with confidence. π
Kisses and chrono arithmetic, Your C++ bestie π
Source: cppreference.com β dated 2024.06.10 β and this page was literally called std::chrono...eekday_last(3) because even manpage titles get abbreviated. Iconic. π
π¦ 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