1

I've got a string representing a date in the format <year>.<day-of-the-year>.<hours>.<minutes>.<seconds>.

Example: 2021.147.17.33.45 is the 27th of May 2021, with time 17:33:45.

How to parse this formatted time string into a std::chrono::system_clock::time_point using Howard Hinnant's date library or the equivalent C++20 functionalities?

I've tried with the following, with no result: the output time_point is always zero.

auto toTimePoint(const std::string& val)
{
    std::istringstream ss(val);
    std::chrono::system_clock::time_point tp;
    std::chrono::from_stream(ss, "%Y.%j.%H.%M.%S", tp)
    return tp;
}

EDIT: This code fails using Visual Studio v16.10 with \std:c++latest, but works correctly using Howard Hinnant's date library (see the comment of T.C. below). I've opened a new issue on the Microsoft STL GitHub repository.

Rackbox
  • 283
  • 1
  • 11
  • 8
    Works for me with date: https://gcc.godbolt.org/z/EfxeG4YPj – T.C. May 27 '21 at 16:24
  • @T.C. Wow! A URL in an `#include`... (I've never seen before.) – Scheff's Cat May 27 '21 at 16:59
  • 2
    @Scheff https://stackoverflow.com/a/59516521/12861639 it says to be a godbolt feature – Ranoiaetep May 27 '21 at 22:35
  • Some context: I have some experience with Howard Hinnant's date library, but when starting a new project I decided to use the allegedly equivalent C++20, shipped with Visual Studio v16.10. The equivalence must therefore be not so strict. Unfortunately there is no way to test the behaviour of VS v16.10 online to show you my point... – Rackbox May 28 '21 at 06:48
  • I've opened a new issue on the Microsoft STL GitHub repository: https://github.com/microsoft/STL/issues/1938 – Rackbox May 28 '21 at 08:46

0 Answers0