Skip to content

<locale>: time_put.put("%r") prints a 24-hour time rather than a 12-hour time #371

@BillyONeal

Description

@BillyONeal

Describe the bug
The C++ standard time_put defers to strftime, and the C standard says that %r is intended to print a 12-hour time. However, we appear to be printing a 24-hour time.

Command-line test case

C:\Users\bion\Desktop>type repro.cpp
#include <iostream>

#include <locale>

using namespace std;

class ctst : public std::time_put<char>{};

int main() {
    ctst stdtp;
    struct tm _tm {
        0, 0, 23, 1, 0, 0, 0, 0, 0
    };
    char format[]{'%', 'r', 0};
    stdtp.put(cout, cout, cout.fill(), &_tm, &format[0], &format[2]);
    cout << '\n';
    stdtp.put(cout, cout, cout.fill(), &_tm, format[1]);
    cout << '\n';
    return 0;
}

C:\Users\bion\Desktop>cl /EHsc .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28314 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.24.28314.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

C:\Users\bion\Desktop>.\repro.exe
23:00:00
23:00:00

Expected behavior
The output should have been a 12-hour time rather than a 24-hour time.

Additional context
It looks like we get the CRT rather than the STL to do most of this processing, so the result may be reducing this to a UCRT test case and submitting that against Windows.

if (0 < (_Count = _Strftime(&_Str[0], _Str.size(), _Fmt, _Pt, _Tnames._Getptr()))) {

This item is also tracked on Developer Community as DevCom-758960 and by Microsoft-internal VSO-998596 / AB#998596.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions