std::chrono...eekday_last(3)

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

✨ 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 years
  • operator-= β€” (public member function) same energy, but subtracting
  • year β€” accesses the fields of this object
  • month β€” 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 a std::chrono::time_point
  • operator local_days β€” (public member function) converts to local days
  • ok β€” 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 two year_month_weekday_last values (C++20) (function)
  • operator+ β€” adds or subtracts a year_month_weekday_last and some number of years or months
  • operator- β€” (C++20) (function) same thing but the other direction
  • operator<< β€” outputs a year_month_weekday_last into 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 for year_month_weekday_last (C++20) (class template specialization). You love to see it. πŸŽ€
  • std::hash<std::chrono::year_month_weekday_last> β€” hash support for std::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