https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121929

            Bug ID: 121929
           Summary: std::format prints a valid-looking date for invalid
                    2020y/January/Friday[10]
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
                CC: tkaminsk at gcc dot gnu.org
  Target Milestone: ---

#include <chrono>
#include <format>
#include <iostream>

int main() {
    using namespace std::chrono;
    auto d = 2020y/January/Friday[10];
    std::cout << local_days(d) - local_days(2020y/January/0) << std::endl; //
"66d"

    std::cout << std::format("{:%Y-%m-%d}", d) << std::endl;
    // prints: "2020-01-06"
    // should print: "2020-01-66"
}

Tomasz writes:

The value of month is fixed, and priting a valid date out of that seems just
wrong. We should turn !okweekoffset into !ok date. Which would not be more
expensive nor harder, just compute day using:
t._M_ldays - local_days(t._M_year/t._M_month/0)
Instead of:
year_month_day(t.Mldays).day()

Reply via email to