The C++20 standard defines 2 types that store a time during the day: chrono::hh_mm_ss
and chrono::time_of_day
.
Both seem to store a duration since midnight, but because of DST-effects, callers should only use the hours, minutes, seconds and subseconds elements.
www.cppreference.com gives exactly the same description for both types:
The class template ... splits a std::chrono::duration representing time since midnight into a "broken down" time such as hours:minutes:seconds, with the precision of the split determined by the Duration template parameter. ... It is primarily a formatting tool.
The only difference seems to be that chrono::time_of_day
mentions 12-hour/24-hour formatting and chrono::hh_mm_ss
doesn't.
In Howard Hinnant's GitHub library time_of_day
is defined like this:
template <class Duration>
using time_of_day = hh_mm_ss<Duration>;
So why have 2 different types for this?
https://en.cppreference.com/w/ is great, but not perfect. Ok, maybe it is. Where else can you get this kind of speed for fixes?! (note the second comment below this answer). :-)
Howard Hinnant's GitHub library originally had just time_of_day
. And that was part of the proposal for C++20. During the standardization process, time_of_day
was renamed to hh_mm_ss
, and a few API adjustments were made.
Here is the paper that proposed these changes: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1466r3.html
Howard Hinnant's GitHub library "implemented" this change, but left a time_of_day
type alias just for backwards compatibility with existing users of this library.
In short, there is no chrono::time_of_day
, there is only chrono::hh_mm_ss
: http://eel.is/c++draft/time.hms
Please note the very helpful comment below from Nicol Bolas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With