diff --git a/stl/inc/chrono b/stl/inc/chrono index db519559289..3906e3b48e3 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -5966,8 +5966,10 @@ namespace chrono { } } - return _Write_aligned(_STD move(_FormatCtx.out()), static_cast(_Stream.view().size()), _Specs, - _Fmt_align::_Left, [&](auto _Out) { return _Fmt_write(_STD move(_Out), _Stream.view()); }); + int _Estimated_width = -1; + (void) _Measure_string_prefix(_Stream.view(), _Estimated_width); + return _Write_aligned(_STD move(_FormatCtx.out()), _Estimated_width, _Specs, _Fmt_align::_Left, + [&](auto _Out) { return _Fmt_write(_STD move(_Out), _Stream.view()); }); } // This echoes the functionality of put_time, but is able to handle invalid dates (when !ok()) since the diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst index 18e2d7c71ec..4ca6faed472 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/env.lst @@ -2,3 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception RUNALL_INCLUDE ..\concepts_latest_matrix.lst +RUNALL_CROSSLIST +PM_CL="/utf-8" diff --git a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp index b16ef15005f..bafd52b032c 100644 --- a/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp +++ b/tests/std/tests/P0355R7_calendars_and_time_zones_formatting/test.cpp @@ -3,9 +3,11 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -29,6 +31,13 @@ template #define STR(Literal) (choose_literal(Literal, L##Literal)) +// Test against IDL mismatch between the DLL which stores the locale and the code which uses it. +#ifdef _DEBUG +#define DEFAULT_IDL_SETTING 2 +#else +#define DEFAULT_IDL_SETTING 0 +#endif + template struct testing_callbacks { _Fmt_align expected_alignment = _Fmt_align::_None; @@ -884,6 +893,12 @@ void test_zoned_time_formatter() { assert(format(STR("{:%g %G %U %V %W}"), zt) == STR("21 2021 16 16 16")); } +template +void test_locale() { + assert(format(locale{"zh-CN"}, STR("{:^22%Y %B %d %A}"), 2021y / June / 16d) + == STR(" 2021 \u516D\u6708 16 \u661F\u671F\u4E09 ")); +} + void test() { test_parse_conversion_spec(); test_parse_conversion_spec(); @@ -955,6 +970,14 @@ void test() { test_zoned_time_formatter(); test_zoned_time_formatter(); + +#if !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING + test_locale(); +#ifndef MSVC_INTERNAL_TESTING // TRANSITION, the Windows version on Contest VMs doesn't always understand ".UTF-8" + assert(setlocale(LC_ALL, ".UTF-8") != nullptr); + test_locale(); +#endif // MSVC_INTERNAL_TESTING +#endif // !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING } int main() {