-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<chrono>: Incorrect output formatting negative years #3166
Comments
I think this is the intended behavior. The |
I agree for %C this is doing the correct thing but this same function is also being used as part of the implementation for %y. |
You're right that the standard says "[t]he last two decimal digits of the year." But in practice this is often interpreted to mean the number of years since the beginning of the century. Obviously these meanings are the same when the year is positive and different when it's negative, so I suspect people sometimes say one thing while meaning another. The original proposal claims " On the whole, there doesn't seems to be a clear consensus for what the result should be, so maybe an LWG issue is needed to clarify. |
It does sound like there should be separate "years since start of century" "nearest century" "truncated century" and "last two decimals of the year" identifiers, even if they are the same in many cases it's really useful for expressing intent. C Standard The C17 draft has slightly different phrasing then the eel.is c++ draft but it matches closer with fmts implementation of the formatting identifiers, specifically it calls for the truncated integer after division by 100 instead of floored division for %C and for %y it mentions that it's 'replaced' by the last 2 digits of the year, that seems much more strictly defined. About the 00 case in FMT, that seems to come from 2 things,
Year formatting in fmt for reference It makes more sense when you read the 2 different versions of the time specs(c vs c++) and try to combine them. |
We talked about this the weekly maintainer meeting and agree that an LWG issue seems necessary here. @MattStephanson would you like to file an issue, or would you like someone else to look into drafting one? |
@StephanTLavavej --- I'll write it up and see if Victor or Howard want to add anything before it's submitted. |
Update for anyone who's watching this issue: I sent out the draft issue yesterday. Waiting to see if one more person wants to comment, but planning to send to LWG by next Monday at the latest. |
Describe the bug
Incorrect values when formatting negative std::chrono::years with %y (last 2 only).
Command-line test case
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
The text was updated successfully, but these errors were encountered: