Skip to content

<iomanip>: get_time should parse format without delimiters #944

@Amaroker

Description

@Amaroker

Command-line test case

#include <iostream>
#include <sstream>
#include <iomanip>
#include <assert.h>

int main()
{
  {
    // Parsing with delimiters (such as spaces) works fine.
    std::tm t = {};
    std::istringstream ss("2020 06 20");
    ss >> std::get_time(&t, "%Y %m %d");
    assert( !ss.fail() );
  }

  {
    // Parsing without delimiters fails, but should work too.
    std::tm t = {};
    std::istringstream ss("20200620");
    ss >> std::get_time(&t, "%Y%m%d");
    if( ss.fail() )
        std::cout << "test failure\n";
  }
}

STL version
Microsoft Visual Studio Professional 2019
Version 16.6.2

Additional context
The standard draft WG21-N4861 says that the conversion specification is valid for the ISO/IEC 9945 function strptime.

Looking at strptime, it says "The application shall ensure that there is white-space or other non-alphanumeric characters between any two conversion specifications unless all of the adjacent conversion specifications convert a known, fixed number of characters."

The number of characters for each conversion specifier is listed.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html

See also: DevCom-9505, DevCom-140618, DevCom-246365 and Microsoft-internal VSO-370548 / AB#370548.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions