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

            Bug ID: 89778
           Summary: std::get_time : %d does not work without leading zeros
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: myLC at gmx dot net
  Target Milestone: ---

#include <ctime>
#include <string>
#include <iomanip>
#include <sstream>
#include <iostream>

void printDate( const std::string &date_string ) {
  std::istringstream is( date_string );
  std::tm tm{};
  static const char *date_format( "%Y/%b/%d" );
  // d : parses the day of the month as a decimal number 
  //     (range [01,31]), leading zeroes permitted but not required 
  is >> std::get_time( &tm, date_format );
  char buf[ 20 ];
  std::strftime( buf, 20, date_format, &tm );
  std::cout << buf << '\n';
}

int main() {
  printDate( "2019/Apr/09" );
  printDate( "2019/Apr/9" );
  std::cout << '\n';
  printDate( "2017/Jan/02" );
  printDate( "2017/Jan/2" );
  std::cout << '\n';
  printDate( "2018/Dec/07" );
  printDate( "2018/Dec/7" );
}


###############


gcc-bug > g++ --version && g++ get_time-bug.cpp -o get_time-bug &&
./get_time-bug
g++ (Ubuntu 8.1.0-5ubuntu1~14.04) 8.1.0 <=== (x86 64-bit)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2019/Apr/09
2019/Apr/00

2017/Jan/02
2017/Jan/00

2018/Dec/07
2018/Dec/00

Reply via email to