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

            Bug ID: 103612
           Summary: get_time parsing error for two digits year
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pyaggi at gmail dot com
  Target Milestone: ---

std::get_time is behaving in the same way when the format includes '%y' or
'%Y', in both cases it tries to read a four digit year.

Example Code:
-------------
#include <iostream>
#include <iomanip>

void testDate(const char *format,const char *date)
{
    std::istringstream ds(date);
    std::tm tm = {};
    ds >> std::get_time(&tm,format);
    std::cout<<date<<" parsed using "<<format<<" -> Year: "<<tm.tm_year+1900<<"
Month: "<<tm.tm_mon<<" Day: "<<tm.tm_mday<<std::endl;
}

int main()
{
    testDate("%y%m%d","101112");
    testDate("%Y%m%d","101112");
    testDate("%y%m%d","20101112");
    testDate("%Y%m%d","20101112");

    return 0;
}

Output:
-------
101112 parsed using %y%m%d -> Year: 1011 Month: 11 Day: 0
101112 parsed using %Y%m%d -> Year: 1011 Month: 11 Day: 0
20101112 parsed using %y%m%d -> Year: 2010 Month: 10 Day: 12
20101112 parsed using %Y%m%d -> Year: 2010 Month: 10 Day: 12

Tested with:
------------
g++ (SUSE Linux) 11.2.1 20210816 
clang++ version 12.0.1

Reply via email to