Bug 71556 - set::get_time() requires leading 0s for %H and friends
Summary: set::get_time() requires leading 0s for %H and friends
Status: RESOLVED DUPLICATE of bug 45896
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.1.1
: P3 normal
Target Milestone: ---
Assignee: Jonathan Wakely
Depends on:
Reported: 2016-06-16 12:41 UTC by Julian Andres Klode
Modified: 2017-07-13 10:04 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2016-06-16 00:00:00

C++ reproducer (202 bytes, text/x-csrc)
2016-06-16 12:41 UTC, Julian Andres Klode

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Andres Klode 2016-06-16 12:41:22 UTC
Created attachment 38713 [details]
C++ reproducer

In contrast to strptime(), std::get_time() requires leading zeroes for %H and friends, so times with " 9" (%k formatting) instead of "09" cannot be parsed. The C++ standard requires get_time() to work like strptime(), as far as I can tell, and cppreference tells us that leading 0s are permitted, but optional.

This means we cannot parse a date like: "Thu, 16 Jun 2016  9:35:47 UTC" which in turn breaks date parsing for recent APT versions when we switched from strptime to std::get_time().
Comment 1 Julian Andres Klode 2016-06-16 12:43:54 UTC
To be clear, while the attachment uses the (I assume still) non-standard C.UTF-8, the same also happens with the C locale, and the "" locale in an en_IE.UTF-8 environment.
Comment 2 Sebastian Unger 2016-11-23 23:48:25 UTC
I also just ran into this. Took me a while to convince myself that I was actually looking at a compiler (well library) bug before searching.

clang does not have this issue.

It also affects %m and %d. Haven't tried any others.
Comment 3 Maxim Egorushkin 2017-07-04 09:44:33 UTC
People keep hitting this bug: https://stackoverflow.com/questions/44901711/convert-ansi-cs-asctime-format-using-stdget-time
Comment 4 Jonathan Wakely 2017-07-13 10:04:22 UTC
The leading zeros were required in C++98, but are optional since C++1.

This is Bug 45896.

*** This bug has been marked as a duplicate of bug 45896 ***