std::chrono...orsys_days,(3)

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

okay bestie, welcome to the page for std::chrono...orsys_days,(3) from the C++ Standard Libary manual ✨ β€” yes, that spelling is exactly what's on the page, and we are keeping it, no cap πŸ’….

πŸ’– NAME πŸ’–

the group-chat names for this one are literally:

std::chrono::year_month_weekday::operatorsys_days, -
std::chrono::year_month_weekday::operatorsys_days,

✨ Synopsis ✨

here's the signature block, exactly as it appears:

          constexpr operator std::chrono::sys_days() const noexcept;
       (1) (since C++20)
          constexpr explicit operator std::chrono::local_days() const
       (2) (since C++20)
          noexcept;

so the vibe is: this converts *this to a std::chrono::time_point representing the same date as this year_month_weekday 🫢.

  1. if year().ok() && month().ok() && weekday().ok():
    • if index() == 0, it returns a sys_days that represents the date 7 days prior to the first weekday() of the year and month ⭐.
    • else, it returns a sys_days that represents the date (index() - 1) * 7 days after the first weekday() of the year and month. otherwise, the returned value is unspecified β€” that's the "do not count on it" vibe, bestie 🫠.
  2. same as (1), but returns local_days instead of sys_days. equivalent to local_days(sys_days(*this).time_since_epoch()).

🌸 Example 🌸

run this code πŸ‘‡

// Run this code

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

        int main()
        {
            constexpr auto ymwd{Tuesday[2]/11/2021};
            std::cout << ymwd << '\n';
            // convert from field-based to serial-based to add hours
            constexpr auto sd = sys_days{ymwd} + 24h;
            std::cout << sd << '\n';
            constexpr auto ymd = floor<days>(sd);
            static_assert(ymd == November/10/2021);
        }

πŸŽ€ Output πŸŽ€

        2021/Nov/Tue[2]
        2021-11-10 00:00:00

source/version/date sign-off, bestie: http://cppreference.com Β· 2024.06.10 Β· std::chrono...orsys_days,(3) β€” byeee, slay responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from