@@ -5232,24 +5232,25 @@ struct _Chrono_spec {
5232
5232
};
5233
5233
5234
5234
template <class _CharT>
5235
- struct _Chrono_format_specs {
5235
+ struct _Chrono_format_specs2 {
5236
5236
int _Width = 0;
5237
5237
int _Precision = -1;
5238
5238
int _Dynamic_width_index = -1;
5239
5239
int _Dynamic_precision_index = -1;
5240
5240
_Fmt_align _Alignment = _Fmt_align::_None;
5241
5241
uint8_t _Fill_length = 1;
5242
+ bool _Localized = false;
5242
5243
// At most one codepoint (so one char32_t or four utf-8 char8_t)
5243
5244
_CharT _Fill[4 / sizeof(_CharT)] = {_CharT{' '}};
5244
5245
// recursive definition in grammar, so could have any number of these
5245
5246
vector<_Chrono_spec<_CharT>> _Chrono_specs_list;
5246
5247
};
5247
5248
5248
- // Model of _Chrono_parse_spec_callbacks that fills a _Chrono_format_specs with the parsed data
5249
+ // Model of _Chrono_parse_spec_callbacks that fills a _Chrono_format_specs2 with the parsed data
5249
5250
template <class _CharT, class _ParseContext>
5250
5251
class _Chrono_specs_setter {
5251
5252
public:
5252
- constexpr explicit _Chrono_specs_setter(_Chrono_format_specs <_CharT>& _Specs_, _ParseContext& _Parse_ctx_)
5253
+ constexpr explicit _Chrono_specs_setter(_Chrono_format_specs2 <_CharT>& _Specs_, _ParseContext& _Parse_ctx_)
5253
5254
: _Specs(_Specs_), _Parse_ctx(_Parse_ctx_) {}
5254
5255
5255
5256
// same as _Specs_setter
@@ -5294,6 +5295,10 @@ public:
5294
5295
_Specs._Dynamic_precision_index = _Verify_dynamic_arg_index_in_range(_Parse_ctx.next_arg_id());
5295
5296
}
5296
5297
5298
+ constexpr void _On_localized() {
5299
+ _Specs._Localized = true;
5300
+ }
5301
+
5297
5302
constexpr void _On_conversion_spec(char _Modifier, _CharT _Type) {
5298
5303
// NOTE: same performance note from _Basic_format_specs also applies here
5299
5304
if (_Modifier != '\0' && _Modifier != 'E' && _Modifier != 'O') {
@@ -5314,7 +5319,7 @@ public:
5314
5319
}
5315
5320
5316
5321
private:
5317
- _Chrono_format_specs <_CharT>& _Specs;
5322
+ _Chrono_format_specs2 <_CharT>& _Specs;
5318
5323
_ParseContext& _Parse_ctx;
5319
5324
5320
5325
_NODISCARD static constexpr int _Verify_dynamic_arg_index_in_range(const size_t _Idx) {
@@ -5375,6 +5380,14 @@ _NODISCARD constexpr const _CharT* _Parse_chrono_format_specs(
5375
5380
}
5376
5381
}
5377
5382
5383
+ if (*_Begin == 'L') {
5384
+ _Callbacks._On_localized();
5385
+ ++_Begin;
5386
+ if (_Begin == _End) {
5387
+ return _Begin;
5388
+ }
5389
+ }
5390
+
5378
5391
if (*_Begin != '}' && *_Begin != '%') {
5379
5392
_THROW(format_error("Invalid format string - chrono-specs must begin with conversion-spec"));
5380
5393
}
@@ -5582,7 +5595,7 @@ namespace chrono {
5582
5595
5583
5596
template <class _CharT, class _Traits>
5584
5597
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const month& _Val) {
5585
- return _Os << (_Val.ok() ? _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:%b}"), _Val)
5598
+ return _Os << (_Val.ok() ? _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %b}"), _Val)
5586
5599
: _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{} is not a valid month"),
5587
5600
static_cast<unsigned int>(_Val)));
5588
5601
}
@@ -5595,7 +5608,7 @@ namespace chrono {
5595
5608
5596
5609
template <class _CharT, class _Traits>
5597
5610
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const weekday& _Val) {
5598
- return _Os << (_Val.ok() ? _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:%a}"), _Val)
5611
+ return _Os << (_Val.ok() ? _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %a}"), _Val)
5599
5612
: _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{} is not a valid weekday"),
5600
5613
_Val.c_encoding()));
5601
5614
}
@@ -5604,40 +5617,41 @@ namespace chrono {
5604
5617
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const weekday_indexed& _Val) {
5605
5618
const auto _Idx = _Val.index();
5606
5619
return _Os << (_Idx >= 1 && _Idx <= 5
5607
- ? _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}[{}]"), _Val.weekday(), _Idx)
5608
- : _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}[{} is not a valid index]"),
5620
+ ? _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }[{}]"), _Val.weekday(), _Idx)
5621
+ : _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }[{} is not a valid index]"),
5609
5622
_Val.weekday(), _Idx));
5610
5623
}
5611
5624
5612
5625
template <class _CharT, class _Traits>
5613
5626
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const weekday_last& _Val) {
5614
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}[last]"), _Val.weekday());
5627
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }[last]"), _Val.weekday());
5615
5628
}
5616
5629
5617
5630
template <class _CharT, class _Traits>
5618
5631
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const month_day& _Val) {
5619
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/{}"), _Val.month(), _Val.day());
5632
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }/{:L }"), _Val.month(), _Val.day());
5620
5633
}
5621
5634
5622
5635
template <class _CharT, class _Traits>
5623
5636
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const month_day_last& _Val) {
5624
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/last"), _Val.month());
5637
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }/last"), _Val.month());
5625
5638
}
5626
5639
5627
5640
template <class _CharT, class _Traits>
5628
5641
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const month_weekday& _Val) {
5629
5642
return _Os << _STD format(
5630
- _Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/{}"), _Val.month(), _Val.weekday_indexed());
5643
+ _Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }/{:L }"), _Val.month(), _Val.weekday_indexed());
5631
5644
}
5632
5645
5633
5646
template <class _CharT, class _Traits>
5634
5647
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const month_weekday_last& _Val) {
5635
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/{}"), _Val.month(), _Val.weekday_last());
5648
+ return _Os << _STD format(
5649
+ _Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), _Val.month(), _Val.weekday_last());
5636
5650
}
5637
5651
5638
5652
template <class _CharT, class _Traits>
5639
5653
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const year_month& _Val) {
5640
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/{}"), _Val.year(), _Val.month());
5654
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }/{:L }"), _Val.year(), _Val.month());
5641
5655
}
5642
5656
5643
5657
template <class _CharT, class _Traits>
@@ -5648,25 +5662,26 @@ namespace chrono {
5648
5662
5649
5663
template <class _CharT, class _Traits>
5650
5664
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const year_month_day_last& _Val) {
5651
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/{}"), _Val.year(), _Val.month_day_last());
5665
+ return _Os << _STD format(
5666
+ _Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L}/{:L}"), _Val.year(), _Val.month_day_last());
5652
5667
}
5653
5668
5654
5669
template <class _CharT, class _Traits>
5655
5670
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const year_month_weekday& _Val) {
5656
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/{}/{}"), _Val.year(), _Val.month(),
5671
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L }/{:L }/{:L }"), _Val.year(), _Val.month(),
5657
5672
_Val.weekday_indexed());
5658
5673
}
5659
5674
5660
5675
template <class _CharT, class _Traits>
5661
5676
basic_ostream<_CharT, _Traits>& operator<<(
5662
5677
basic_ostream<_CharT, _Traits>& _Os, const year_month_weekday_last& _Val) {
5663
- return _Os << _STD format(
5664
- _Os.getloc(), _STATICALLY_WIDEN(_CharT, "{}/{}/{}"), _Val.year(), _Val.month(), _Val.weekday_last());
5678
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L}/{:L}/{:L}"), _Val.year(), _Val.month(),
5679
+ _Val.weekday_last());
5665
5680
}
5666
5681
5667
5682
template <class _CharT, class _Traits, class _Duration>
5668
5683
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const hh_mm_ss<_Duration>& _Val) {
5669
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:%T}"), _Val);
5684
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %T}"), _Val);
5670
5685
}
5671
5686
5672
5687
#pragma warning(push)
@@ -5717,7 +5732,7 @@ namespace chrono {
5717
5732
// clang-format on
5718
5733
const auto _Dp = _CHRONO floor<days>(_Val);
5719
5734
return _Os << _STD format(
5720
- _Os.getloc(), _STATICALLY_WIDEN(_CharT, "{} {}"), year_month_day{_Dp}, hh_mm_ss{_Val - _Dp});
5735
+ _Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L } {:L }"), year_month_day{_Dp}, hh_mm_ss{_Val - _Dp});
5721
5736
}
5722
5737
5723
5738
template <class _CharT, class _Traits>
@@ -5727,22 +5742,22 @@ namespace chrono {
5727
5742
5728
5743
template <class _CharT, class _Traits, class _Duration>
5729
5744
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const utc_time<_Duration>& _Val) {
5730
- return _Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:%F %T}"), _Val);
5745
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %F %T}"), _Val);
5731
5746
}
5732
5747
5733
5748
template <class _CharT, class _Traits, class _Duration>
5734
5749
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const tai_time<_Duration>& _Val) {
5735
- return _Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:%F %T}"), _Val);
5750
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %F %T}"), _Val);
5736
5751
}
5737
5752
5738
5753
template <class _CharT, class _Traits, class _Duration>
5739
5754
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const gps_time<_Duration>& _Val) {
5740
- return _Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:%F %T}"), _Val);
5755
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %F %T}"), _Val);
5741
5756
}
5742
5757
5743
5758
template <class _CharT, class _Traits, class _Duration>
5744
5759
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& _Os, const file_time<_Duration>& _Val) {
5745
- return _Os << _STD format(_STATICALLY_WIDEN(_CharT, "{:%F %T}"), _Val);
5760
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %F %T}"), _Val);
5746
5761
}
5747
5762
5748
5763
template <class _CharT, class _Traits, class _Duration>
@@ -5755,7 +5770,7 @@ namespace chrono {
5755
5770
basic_ostream<_CharT, _Traits>& _Os, const _Local_time_format_t<_Duration>& _Val) {
5756
5771
// Doesn't appear in the Standard, but allowed by N4885 [global.functions]/2.
5757
5772
// Implements N4885 [time.zone.zonedtime.nonmembers]/2 for zoned_time.
5758
- return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:%F %T %Z}"), _Val);
5773
+ return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L %F %T %Z}"), _Val);
5759
5774
}
5760
5775
5761
5776
template <class _CharT, class _Traits, class _Duration, class _TimeZonePtr>
@@ -5899,10 +5914,10 @@ namespace chrono {
5899
5914
_NODISCARD auto _Write(_FormatContext& _FormatCtx, const _Ty& _Val, const tm& _Time) {
5900
5915
basic_ostringstream<_CharT> _Stream;
5901
5916
5917
+ _Stream.imbue(_Specs._Localized ? _FormatCtx.locale() : locale::classic());
5902
5918
if (_Specs._Chrono_specs_list.empty()) {
5903
5919
_Stream << _Val; // N4885 [time.format]/6
5904
5920
} else {
5905
- _Stream.imbue(_FormatCtx.locale());
5906
5921
if constexpr (_Is_specialization_v<_Ty, hh_mm_ss>) {
5907
5922
if (_Val.is_negative()) {
5908
5923
_Stream << _CharT{'-'};
@@ -6262,7 +6277,7 @@ namespace chrono {
6262
6277
return _Fmt_str;
6263
6278
}
6264
6279
6265
- _Chrono_format_specs <_CharT> _Specs{};
6280
+ _Chrono_format_specs2 <_CharT> _Specs{};
6266
6281
basic_string_view<_CharT> _Time_zone_abbreviation{};
6267
6282
};
6268
6283
} // namespace chrono
0 commit comments