@@ -1601,12 +1601,12 @@ namespace chrono {
1601
1601
1602
1602
constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
1603
1603
constexpr explicit hh_mm_ss(_Duration _Dur)
1604
- : _Is_neg{_Dur < _Duration::zero()}, //
1604
+ : _Is_neg{_Dur < _Duration::zero()},
1605
1605
_Hours{_Duration_cast_underflow_to_zero<_CHRONO hours>(_CHRONO abs(_Dur))},
1606
1606
_Mins{_Duration_cast_underflow_to_zero<_CHRONO minutes>(
1607
1607
_Remove_duration_part<_CHRONO hours>(_CHRONO abs(_Dur)))},
1608
1608
_Secs{_Duration_cast_underflow_to_zero<_CHRONO seconds>(
1609
- _Remove_duration_part<_CHRONO minutes>(_CHRONO abs(_Dur)))} {
1609
+ _Remove_duration_part<_CHRONO minutes>(_Remove_duration_part< _CHRONO hours>(_CHRONO abs(_Dur) )))} {
1610
1610
if constexpr (treat_as_floating_point_v<typename precision::rep>) {
1611
1611
// no need to deal with underflow here, because floating durations allow it
1612
1612
_Sub_secs = _CHRONO abs(_Dur) - hours() - minutes() - seconds();
@@ -4942,11 +4942,6 @@ namespace chrono {
4942
4942
_STL_INTERNAL_CHECK(false);
4943
4943
}
4944
4944
4945
- template <class _Duration>
4946
- _NODISCARD constexpr auto _Hh_mm_ss_part_underflow_to_zero(const _Duration& _Val) {
4947
- return hh_mm_ss<common_type_t<days, _Duration>>{_Remove_duration_part<days>(_Val)};
4948
- }
4949
-
4950
4945
template <unsigned int _Fractional_width, class _CharT, class _Traits, class _Precision>
4951
4946
void _Write_fractional_seconds(
4952
4947
basic_ostream<_CharT, _Traits>& _Os, const seconds& _Seconds, const _Precision& _Subseconds) {
@@ -4993,7 +4988,7 @@ namespace chrono {
4993
4988
4994
4989
template <class _CharT, class _Traits, class _Rep, class _Period>
4995
4990
void _Write_seconds(basic_ostream<_CharT, _Traits>& _Os, const duration<_Rep, _Period>& _Val) {
4996
- _Write_seconds(_Os, _Hh_mm_ss_part_underflow_to_zero( _Val) );
4991
+ _Write_seconds(_Os, hh_mm_ss{ _Val} );
4997
4992
}
4998
4993
4999
4994
template <class _Ty>
@@ -5008,7 +5003,7 @@ namespace chrono {
5008
5003
int _Seconds = 0;
5009
5004
5010
5005
if constexpr (_Is_specialization_v<_Ty, duration>) {
5011
- return _Fill_tm(_Hh_mm_ss_part_underflow_to_zero( _Val) );
5006
+ return _Fill_tm(hh_mm_ss{ _Val} );
5012
5007
} else if constexpr (_Is_specialization_v<_Ty, _Local_time_format_t>) {
5013
5008
return _Fill_tm(_Val._Time);
5014
5009
} else if constexpr (is_same_v<_Ty, day>) {
@@ -5616,10 +5611,13 @@ namespace chrono {
5616
5611
_Os << _CharT{'/'};
5617
5612
_Custom_write(_Os, {._Type = 'y'}, _Time, _Val);
5618
5613
return true;
5614
+ case 'H':
5615
+ // Print hour even if >= 24.
5616
+ _Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:02}"), _Time.tm_hour);
5617
+ return true;
5619
5618
case 'T':
5620
- // Alias for %H:%M:%S but we need to rewrite %S to display fractions of a second.
5621
- _Validate_specifiers({._Type = 'H'}, _Val);
5622
- _Os << _STD put_time(&_Time, _STATICALLY_WIDEN(_CharT, "%H:%M:"));
5619
+ // Alias for %H:%M:%S but we allow hours > 23 and rewrite %S to display fractions of a second.
5620
+ _Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:02}:{:02}:"), _Time.tm_hour, _Time.tm_min);
5623
5621
[[fallthrough]];
5624
5622
case 'S':
5625
5623
if (_Has_modifier) {
@@ -5674,14 +5672,8 @@ namespace chrono {
5674
5672
template <class _Ty>
5675
5673
static void _Validate_specifiers(const _Chrono_spec<_CharT>& _Spec, const _Ty& _Val) {
5676
5674
if constexpr (_Is_specialization_v<_Ty, duration> || is_same_v<_Ty, sys_info>
5677
- || _Is_specialization_v<_Ty, time_point> || _Is_specialization_v<_Ty, _Local_time_format_t>) {
5678
- return;
5679
- }
5680
-
5681
- if constexpr (_Is_specialization_v<_Ty, hh_mm_ss>) {
5682
- if (_Spec._Type == 'H' && _Val.hours() >= hours{24}) {
5683
- _Throw_format_error("Cannot localize hh_mm_ss with an absolute value of 24 hours or more.");
5684
- }
5675
+ || _Is_specialization_v<_Ty, time_point> || _Is_specialization_v<_Ty, _Local_time_format_t>
5676
+ || _Is_specialization_v<_Ty, hh_mm_ss>) {
5685
5677
return;
5686
5678
}
5687
5679
0 commit comments