HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.11k stars 673 forks source link

to_stream(os, "%X", ymd) should not output something to os #393

Open kivadiu opened 5 years ago

kivadiu commented 5 years ago

If I use to_stream(os, "%X", ymd), I get the 00:00:00 in os in addition to a failbit while to_stream(os, "%c", ymd) just sets failbit without outputing anything. I suspect that I get a failbit because there is no time information in ymd and %X means "The locale's time representation"; this seems reasonable to me. However in case of an error, shouldn't we avoid any output at all?

This programs shows the different behaviour of the different formats: date_to_stream.cpp.gz Here is the output I get both with g++ 8.2.0 and with clang++ 6.0.1 on linux x86_64:

$ ./date_to_stream
to_stream(%c): failed
to_stream(%Ec): failed
to_stream(%X): 00:00:00failed
to_stream(%x): 06/15/18
to_stream(%Ex): 06/15/18
HowardHinnant commented 5 years ago

Yes, you are correct.