-
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>
: Formatting large hh_mm_ss
values should be permitted
#3676
Comments
StephanTLavavej
added
bug
Something isn't working
format
C++20/23 format
chrono
C++20 chrono
labels
Apr 27, 2023
Thanks Stephan.
Did you also look at the inconsistencies of using std::format()?
Am 27. April 2023 22:10:14 MESZ schrieb "Stephan T. Lavavej" ***@***.***>:
Reported by @josuttis to the LWG mailing list. @HowardHinnant confirmed that this is a bug. After checking the Standard, I agree that I don't see any direct justification for the exception that we're throwing. \[tab:time.format.spec\] simply says "`%H` The hour (24-hour clock) as a decimal number. If the result is a single digit, it is prefixed with `0`." and the parenthetical "(24-hour clock)" doesn't seem to justify emitting an error. (If the type contains information, we should print it.)
```
C:\Temp>type meow.cpp
```
```cpp
#include <chrono>
#include <format>
#include <iostream>
using namespace std;
int main() {
try {
const chrono::days d{3};
const chrono::hh_mm_ss hms{d};
cout << "d: " << d << "\n";
cout << "hms: " << hms << "\n";
} catch (const format_error& fe) {
cout << fe.what() << "\n";
}
}
```
```
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od meow.cpp && meow
meow.cpp
d: 3d
hms: Cannot localize hh_mm_ss with an absolute value of 24 hours or more.
```
Compare https://godbolt.org/z/WjsPGP771 where libstdc++ prints:
```
d: 3d
hms: 72:00:00
```
The fix may be as simple as removing this code:
https://github.com/microsoft/STL/blob/0a2d59ed7bfe099199237090998b758c9b0b7403/stl/inc/chrono#L5683-L5688
--
Reply to this email directly or view it on GitHub:
#3676
You are receiving this because you were mentioned.
Message ID: ***@***.***>
--
Nico Josuttis
(sent from my mobile phone)
|
inconsistencies of using |
In the discussion I added:
std::chrono::days d{3};
std::cout << "3 days: "<< std::format("{:%T}\n", d);
gcc:
3 days: 72:00:00
VC++:
3 days: 00:00:00
Or is this the same bug?
Am 28.04.2023 um 10:44 schrieb S. B. Tam:
inconsistencies of using |std::format()|? Sounds like LWG-3856
<https://cplusplus.github.io/LWG/issue3856>
—
Reply to this email directly, view it on GitHub
<#3676 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHXEUYZYPRXOYFSYI5IIJTXDN7NTANCNFSM6AAAAAAXOKXIGU>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
---
Nicolai M. Josuttis
www.josuttis.de
+49 (0)531 / 129 88 86
+49 (0)700 / JOSUTTIS
Books:
C++:http://cppstd20.com,http://cppstd17.com,http://cppmove.com,
http://cppstdlib.com,http://tmplbook.com
|
It's likely the same bug but we can check when we're looking at a fix. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reported by @josuttis to the LWG mailing list. @HowardHinnant confirmed that this is a bug. After checking the Standard, I agree that I don't see any direct justification for the exception that we're throwing. [tab:time.format.spec] simply says "
%H
The hour (24-hour clock) as a decimal number. If the result is a single digit, it is prefixed with0
." and the parenthetical "(24-hour clock)" doesn't seem to justify emitting an error. (If the type contains information, we should print it.)Compare https://godbolt.org/z/WjsPGP771 where libstdc++ prints:
The fix may be as simple as removing this code:
STL/stl/inc/chrono
Lines 5683 to 5688 in 0a2d59e
The text was updated successfully, but these errors were encountered: