public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/105450] New: get_time %y reads more than 2 digits (and differ from strptime)
@ 2022-05-02  4:25 fsb4000 at yandex dot ru
  2022-05-02  4:36 ` [Bug libstdc++/105450] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: fsb4000 at yandex dot ru @ 2022-05-02  4:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105450

            Bug ID: 105450
           Summary: get_time %y reads more than 2 digits (and differ from
                    strptime)
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fsb4000 at yandex dot ru
  Target Milestone: ---

Hi.

MattStephanson found that std::get_time with %y differ from strptime.

I decided to inform you.

https://godbolt.org/z/YaMM5PdnT

```c++
#include <ctime>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

void test_get_time(const vector<string>& dates) {
    for (const auto& date : dates) {
        tm time{};
        istringstream iss{date};
        iss >> get_time(&time, "%y");
        cout << "get_time: \"" << date << "\"; 1900 + time.tm_year: " << 1900 +
time.tm_year << endl;
    }
}

void test_get_year(const vector<string>& dates) {
    const auto& f = use_facet<time_get<char>>(locale{});
    for (const auto& date : dates) {
        tm time{};
        ios_base::iostate err = ios_base::goodbit;
        istringstream iss{date};
        f.get_year({iss}, {}, iss, err, &time);
        cout << "get_year: \"" << date << "\"; 1900 + time.tm_year: " << 1900 +
time.tm_year << endl;
    }
}

void test_strptime(const vector<string>& dates) {
    for (const auto& date : dates) {
        tm time{};
        strptime(date.c_str(), "%y", &time);
        cout << "strptime: \"" << date << "\"; 1900 + time.tm_year: " << 1900 +
time.tm_year << endl;
    }
}

int main() {
    vector<string> dates = {"1"s, "01"s, "85"s, "085"s, "111"s};
    test_get_time(dates);
    cout << '\n';
    test_get_year(dates);
    cout << '\n';
    test_strptime(dates);
}
```

This code prints:

get_time: "085"; 1900 + time.tm_year: 85
get_time: "111"; 1900 + time.tm_year: 111

and

strptime: "085"; 1900 + time.tm_year: 2008
strptime: "111"; 1900 + time.tm_year: 2011

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/105450] get_time %y reads more than 2 digits (and differ from strptime)
  2022-05-02  4:25 [Bug libstdc++/105450] New: get_time %y reads more than 2 digits (and differ from strptime) fsb4000 at yandex dot ru
@ 2022-05-02  4:36 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-02  4:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105450

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 103612.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-02  4:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02  4:25 [Bug libstdc++/105450] New: get_time %y reads more than 2 digits (and differ from strptime) fsb4000 at yandex dot ru
2022-05-02  4:36 ` [Bug libstdc++/105450] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).