Skip to content

Commit ac971a3

Browse files
Implement LWG-4124 Cannot format zoned_time with resolution coarser than seconds (#5155)
1 parent a4ae6c3 commit ac971a3

File tree

2 files changed

+9
-4
lines changed
  • stl/inc
  • tests/std/tests/P0355R7_calendars_and_time_zones_formatting

2 files changed

+9
-4
lines changed

stl/inc/chrono

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5270,7 +5270,7 @@ namespace chrono {
52705270
basic_ostream<_CharT, _Traits>& operator<<(
52715271
basic_ostream<_CharT, _Traits>& _Os, const zoned_time<_Duration, _TimeZonePtr>& _Val) {
52725272
const auto _Info = _Val.get_info();
5273-
return _Os << _Local_time_format_t<_Duration>{_Val.get_local_time(), &_Info.abbrev};
5273+
return _Os << _Local_time_format_t<common_type_t<_Duration, seconds>>{_Val.get_local_time(), &_Info.abbrev};
52745274
}
52755275

52765276
template <class _CharT>
@@ -6113,11 +6113,10 @@ constexpr bool enable_nonlocking_formatter_optimization<_CHRONO _Local_time_form
61136113

61146114
template <class _Duration, class _TimeZonePtr, _Format_supported_charT _CharT>
61156115
struct formatter<_CHRONO zoned_time<_Duration, _TimeZonePtr>, _CharT>
6116-
: formatter<_CHRONO _Local_time_format_t<_Duration>, _CharT> {
6117-
6116+
: formatter<_CHRONO _Local_time_format_t<common_type_t<_Duration, _CHRONO seconds>>, _CharT> {
61186117
template <class _FormatContext>
61196118
auto format(const _CHRONO zoned_time<_Duration, _TimeZonePtr>& _Val, _FormatContext& _FormatCtx) const {
6120-
using _Mybase = formatter<_CHRONO _Local_time_format_t<_Duration>, _CharT>;
6119+
using _Mybase = formatter<_CHRONO _Local_time_format_t<common_type_t<_Duration, _CHRONO seconds>>, _CharT>;
61216120
const auto _Info = _Val.get_info();
61226121
return _Mybase::format({_Val.get_local_time(), &_Info.abbrev, &_Info.offset}, _FormatCtx);
61236122
}

tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,12 @@ void test_zoned_time_formatter() {
10201020
== STR("04/19/21 2021-04-19, 2021 20 21, Apr April Apr 04, 19 19, Mon Monday 1 1"));
10211021
assert(format(STR("{:%H %I %M %S, %r, %R %T %p}"), zt) == STR("08 08 16 17, 08:16:17 AM, 08:16 08:16:17 AM"));
10221022
assert(format(STR("{:%g %G %U %V %W}"), zt) == STR("21 2021 16 16 16"));
1023+
1024+
// LWG-4124 "Cannot format zoned_time with resolution coarser than seconds"
1025+
1026+
const zoned_time<minutes> zoned_minutes_epoch{};
1027+
1028+
empty_braces_helper(zoned_minutes_epoch, STR("1970-01-01 00:00:00 UTC"));
10231029
}
10241030

10251031
template <typename CharT>

0 commit comments

Comments
 (0)