A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/microsoft/STL/issues/3166 below:

Incorrect output formatting negative years · Issue #3166 · microsoft/STL · GitHub

Describe the bug
Incorrect values when formatting negative std::chrono::years with %y (last 2 only).

Command-line test case

C:\Temp2>type repro.cpp
#include <chrono>
#include <format>
#include <iostream>

int main() {
 std::chrono::year y1{-3053};
 std::cout << std::format("{:%y}", y1);
 return 0;
}
C:\Temp2>cl /EHsc /W4 /WX /std:c++20 .\repro.cpp & repro.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31630 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.33.31630.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj
47

Expected behavior
Would expect it to print 53

STL version
Microsoft Visual Studio Community 2022 Version 17.3.6 https://github.com/microsoft/STL/tree/main

Additional context
Current code in master:
https://github.com/microsoft/STL/blob/2f8342a3a57fb157d881c6a2d42a917d20e413f8/stl/inc/chrono#L3168

Not sure about the reason for the +100 currently there but would expect something along these lines

_NODISCARD static pair<int, int> _Decompose_year(const int _Year)
{
    int _Two_d_year = _Year % 100;
    return { _Year - _Two_d_year, abs(_Two_d_year) };
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4