Skip to content

D2372R1: Fixing locale handling in chrono formatters #1891

@vitaut

Description

@vitaut

Describe the bug

Chrono formatting depends on locale by default and doesn't provide control over locale which is inconsistent with all the other standard formatters (https://cplusplus.github.io/LWG/issue3547).

Command-line test case

C:\test>type test.cc
#include <chrono>
#include <format>
#include <iostream>

int main() {
  std::locale::global(std::locale("ru_RU"));
  std::cout << std::format("{}\n", 0.042);
  std::cout << std::format("{:%S}\n", std::chrono::milliseconds(42));
}

C:\test>cl test.cc /std:c++latest /I STL/stl/inc STL/stl/src/format.cpp /EHsc
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.29917 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

cl : Command line warning D9026 : options apply to entire command line
test.cc
format.cpp
Generating Code...
Microsoft (R) Incremental Linker Version 14.29.29917.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
format.obj

C:\test>test
0.042
00,042

Expected behavior

Expected the output to be

0.042
00.042

i.e. not depend on the locale.

STL version

f675d68

Metadata

Metadata

Assignees

No one assigned

    Labels

    LEWG issue neededA design defect that should be submitted to LEWG as a new issuechronoC++20 chronoformatC++20/23 format

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions