std::chrono...eekday_last(3)

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

πŸ’– NAME πŸ’–

Okay so this is a page from the C++ Standard Libary manual β€” yes, that’s the manual name, folded in near the top like a little name tag β€” and the page tag is std::chrono...eekday_last(3).

The full NAME situation is std::chrono::month_weekday_last::month,std::chrono::month_weekday_last::weekday_last β€” both of those, together, no cap β€” and the description side of the dash is literally std::chrono::month_weekday_last::month,std::chrono::month_weekday_last::weekday_last. Periodt. πŸ’…


🌸 Synopsis 🌸

These are the two member functions, and they’re both constexpr plus noexcept, since C++20. Iconic behavior, honestly.

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

(1) (since C++20)

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

(2) (since C++20)

Both of these retrieve a copy of the month and weekday_last objects stored in *this. That’s the whole vibe. πŸ¦‹


πŸ’– Return value πŸ’–

  1. A copy of the std::chrono::month object stored in *this.
  2. A copy of the std::chrono::weekday_last object stored in *this.

πŸ¦‹ Example πŸ¦‹

Run this code, bestie β€” it’s giving β€œlast Friday agenda” energy:

// Run this code

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

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

    auto mwdl{March/Friday[last]}; // Last Friday in a March
    auto ywdl{year(2024)/mwdl};
    std::cout << (year_month_day{ywdl} ==
                  year_month_day{March/29/2024}) << ' ';
    // Last Friday of the next month, in 2024
    mwdl = {(mwdl.month() + months(1))/mwdl.weekday_last()};
    ywdl = {year(2024)/mwdl};
    std::cout << (year_month_day{ywdl} ==
                  year_month_day{April/26/2024}) << '\n';
}

πŸ“ Output πŸ“

true true

Sign-off tea β˜•: source/version http://cppreference.com, date 2024.06.10, and page tag std::chrono...eekday_last(3). Bye bestie, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from