microsoft / microsoft/STL

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

Open
#371 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

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.

https://github.com/microsoft/STL/blob/aa0a7a3d859ade0f6f1ff13aa4ef74b3d5ce2326/stl/inc/xloctime#L729

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at stl/inc/xloctime around the linked formatting code and run the supplied C++ command-line reproduction. Determine whether the incorrect %r output is produced by the STL or the CRT/UCRT; done means obtaining 12-hour output or reducing the issue to a UCRT test case for Windows.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
localization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.