This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/79833] New: std::put_time has the wrong values for 2 digit years


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

            Bug ID: 79833
           Summary: std::put_time has the wrong values for 2 digit years
           Product: gcc
           Version: 6.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jllansf at lirr dot org
  Target Milestone: ---

When using the %y specifier on the std::put_time function the documentation
both for std::put_time and the posix strptime() read:

y:  The last two digits of the year. When format contains neither a C
conversion specifier nor a Y conversion specifier, values in the range [69,99]
shall refer to years 1969 to 1999 inclusive and values in the range [00,68]
shall refer to years 2000 to 2068 inclusive;

Running the following sample code:

int main(int argc, char * argv[]) {
        std::tm t = {0};
        std::istringstream ss("03/03/17 11:03:16");
        ss.imbue(std::locale("en_US.UTF8"));
        ss >> std::get_time(&t, "%m/%d/%y %H:%M:%S");

        if (ss.fail()) {
                std::cout << "Parse failed\n";
        } else {
                std::cout << std::put_time(&t, "%c") << '\n';
        }
}

Yields:  "Sun Mar  3 11:03:16 1917"

When based on the documentation since 17, is in the [00,68] range it should
instead Result in the value "Sun Mar  3 11:03:16 2017"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]