std::chrono...iso_encoding(3)

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

okay bestie, welcome to the std::chrono...iso_encoding(3) page from the C++ Standard Libary manual β€” yes, that's the manual name folded in right here so we don't copy the whole header line. ✨

πŸ’– NAME πŸ’–

  • std::chrono::weekday::c_encoding,std::chrono::weekday::iso_encoding β€” std::chrono::weekday::c_encoding,std::chrono::weekday::iso_encoding

Not me keeping the duplicated NAME line exactly as it is, because bestie: facts are facts and the name is the name. πŸ’…

✨ Synopsis ✨

Both of these are constexpr and noexcept, and both are since C++20. Here's the exact signature vibe:

constexpr unsigned c_encoding() const noexcept;   (1) (since C++20)
constexpr unsigned iso_encoding() const noexcept; (2) (since C++20)
  1. Returns the weekday value stored in *this.
  2. Returns the weekday value stored in *this, except that Sunday (stored as 0) is interpreted as 7 according to ISO 8601.

So like, c_encoding() is the plain stored value, and iso_encoding() does the Sunday glow-up. Iconic. 🌸

πŸŽ€ Return value πŸŽ€

  1. The weekday value stored in *this.
  2. c_encoding() == 0u ? 7u : c_encoding()

That's it. That's the whole return-value section. Slay. πŸ’…

πŸ¦‹ Example πŸ¦‹

The page literally says // Run this code, so run it, bestie:

#include <chrono>
#include <iostream>

int main()
{
    std::cout << "i: C: ISO: Weekday:\n";

    for (unsigned i{0}; i != 8; ++i)
    {
        const std::chrono::weekday w{i};
        std::cout << i << "  "
                  << w.c_encoding() << "  "
                  << w.iso_encoding() << "    "
                  << w << '\n';
    }
}

🌈 Output 🌈

i: C: ISO: Weekday:
0  0  7    Sun
1  1  1    Mon
2  2  2    Tue
3  3  3    Wed
4  4  4    Thu
5  5  5    Fri
6  6  6    Sat
7  0  7    Sun

The way the table goes from 7 back to Sun is highkey a vibe check. 🫢


kisses and good vibes πŸ’– β€” this one came from http://cppreference.com, dated 2024.06.10, and its footer title is std::chrono...iso_encoding(3). Periodt. πŸ‘‘

πŸ“¦ where this page comes from