Skip to content
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>: Make format() accept %X and %EX for duration and hh_mm_ss #4250

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -5398,7 +5398,7 @@ namespace chrono {
|| _Is_valid_type<month>(_Type) || _Is_valid_type<day>(_Type) || _Is_valid_type<weekday>(_Type);
} else if constexpr (_Is_specialization_v<_Ty, hh_mm_ss>) {
return _Type == 'H' || _Type == 'I' || _Type == 'M' || _Type == 'S' || _Type == 'r' || _Type == 'R'
|| _Type == 'T' || _Type == 'p';
|| _Type == 'T' || _Type == 'p' || _Type == 'X';
} else if constexpr (_Is_any_of_v<_Ty, sys_info, local_info>) {
return _Type == 'z' || _Type == 'Z';
} else if constexpr (_Is_specialization_v<_Ty, time_point>) {
Expand All @@ -5407,7 +5407,7 @@ namespace chrono {
return true;
}
}
return _Type == 'c' || _Type == 'X' || _Is_valid_type<year_month_day>(_Type)
return _Type == 'c' || _Is_valid_type<year_month_day>(_Type)
|| _Is_valid_type<hh_mm_ss<seconds>>(_Type);
} else if constexpr (_Is_specialization_v<_Ty, _Local_time_format_t>) {
return _Type == 'z' || _Type == 'Z' || _Is_valid_type<decltype(_Ty::_Time)>(_Type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ void test_duration_formatter() {
assert(format(STR("{:%T %j}"), -days{4} - 23h - 30min) == STR("-119:30:00 4"));
assert(format(STR("{:%T %j}"), duration<float, days::period>{1.55f}) == STR("37:11:59 1"));
assert(format(STR("{:%T %j}"), duration<float, days::period>{-1.55f}) == STR("-37:11:59 1"));

// GH-4247: <chrono>: format() should accept %X and %EX for duration and hh_mm_ss
assert(format(STR("{:%X}"), 9h + 7min + 5s) == STR("09:07:05"));
assert(format(STR("{:%EX}"), 9h + 7min + 5s) == STR("09:07:05"));
}

template <typename CharT>
Expand Down Expand Up @@ -765,6 +769,10 @@ void test_hh_mm_ss_formatter() {
assert(format(STR("{:%H}"), hh_mm_ss{24h}) == STR("24"));
assert(format(STR("{:%H}"), hh_mm_ss{-24h}) == STR("-24"));
assert(format(STR("{:%M %S}"), hh_mm_ss{27h + 12min + 30s}) == STR("12 30"));

// GH-4247: <chrono>: format() should accept %X and %EX for duration and hh_mm_ss
assert(format(STR("{:%X}"), hh_mm_ss{9h + 7min + 5s}) == STR("09:07:05"));
assert(format(STR("{:%EX}"), hh_mm_ss{9h + 7min + 5s}) == STR("09:07:05"));
}

void test_exception_classes() {
Expand Down