Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • biboumi biboumi
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Graph
    • Compare
  • Issues 100
    • Issues 100
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • louiz’
  • biboumibiboumi
  • Issues
  • #3215
Closed
Open
Issue created Oct 10, 2016 by louiz’@louizOwner

Datetime parsing with strptime is apparently not portable.

With the following code:

#include <ctime>
#include <string>
#include <iostream>

std::time_t parse_datetime(const char* format, const std::string& stamp)
{
  struct tm tm;
  auto res = ::strptime(stamp.data(), format, &tm);
  if (!res)
    return -1;
  return ::timegm(&tm);
}

auto test(const std::string& stamp)
{
  const char* big_z = "%FT%T%Z";
  const char* small_z = "%FT%T%z";

  std::cout << "[" << stamp << "]" << " with [" << big_z << "]";
  std::cout << " --> " << parse_datetime(big_z, stamp) << std::endl;

  std::cout << "[" << stamp << "]" << " with [" << small_z << "]";
  std::cout << " --> " << parse_datetime(small_z, stamp) << std::endl;

}


int main()
{
  test("1970-01-01T00:00:00z");
  test("1970-01-01T00:00:00Z");
  test("1970-01-01T00:00:00UTC");
  test("1970-01-01T00:00:00");
}

OpenBSD 6.0,:

[1970-01-01T00:00:00z] with [%FT%T%Z] --> -1
[1970-01-01T00:00:00z] with [%FT%T%z] --> -1
[1970-01-01T00:00:00Z] with [%FT%T%Z] --> -1 
[1970-01-01T00:00:00Z] with [%FT%T%z] --> 0  
[1970-01-01T00:00:00UTC] with [%FT%T%Z] --> 0
[1970-01-01T00:00:00UTC] with [%FT%T%z] --> 0
[1970-01-01T00:00:00] with [%FT%T%Z] --> -1
[1970-01-01T00:00:00] with [%FT%T%z] --> -1 

Fedora 24

[1970-01-01T00:00:00z] with [%FT%T%Z] --> 0
[1970-01-01T00:00:00z] with [%FT%T%z] --> -1
[1970-01-01T00:00:00Z] with [%FT%T%Z] --> 0
[1970-01-01T00:00:00Z] with [%FT%T%z] --> 0
[1970-01-01T00:00:00UTC] with [%FT%T%Z] --> 0
[1970-01-01T00:00:00UTC] with [%FT%T%z] --> -1
[1970-01-01T00:00:00] with [%FT%T%Z] --> 0
[1970-01-01T00:00:00] with [%FT%T%z] --> -1

Debian

[1970-01-01T00:00:00z] with [%FT%T%Z] --> 0   
[1970-01-01T00:00:00z] with [%FT%T%z] --> -1  
[1970-01-01T00:00:00Z] with [%FT%T%Z] --> 0   
[1970-01-01T00:00:00Z] with [%FT%T%z] --> -1  
[1970-01-01T00:00:00UTC] with [%FT%T%Z] --> 0 
[1970-01-01T00:00:00UTC] with [%FT%T%z] --> -1
[1970-01-01T00:00:00] with [%FT%T%Z] --> 0    
[1970-01-01T00:00:00] with [%FT%T%z] --> -1   

FreeBSD 11.0

[1970-01-01T00:00:00z] with [%FT%T%Z] --> 0     
[1970-01-01T00:00:00z] with [%FT%T%z] --> -1    
[1970-01-01T00:00:00Z] with [%FT%T%Z] --> -1    
[1970-01-01T00:00:00Z] with [%FT%T%z] --> -1    
[1970-01-01T00:00:00UTC] with [%FT%T%Z] --> 3600
[1970-01-01T00:00:00UTC] with [%FT%T%z] --> -1  
[1970-01-01T00:00:00] with [%FT%T%Z] --> 0      
[1970-01-01T00:00:00] with [%FT%T%z] --> -1     
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking