From f69ced315184a8f02162b8500781d331b00abc0a Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 28 Apr 2023 11:00:01 +0200 Subject: [PATCH] Add strptime for use under Windows --- main/main.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/main/main.cpp b/main/main.cpp index a0c8cd7..97e5a15 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,4 +1,29 @@ -#include "calculate_price.h" +#include + + +#ifdef WIN32 +#include +#include +#include + +extern "C" char* strptime(const char* s, + const char* f, + struct tm* tm) { + // Isn't the C++ standard lib nice? std::get_time is defined such that its + // format parameters are the exact same as strptime. Of course, we have to + // create a string stream first, and imbue it with the current C locale, and + // we also have to make sure we return the right things if it fails, or + // if it succeeds, but this is still far simpler an implementation than any + // of the versions in any of the C standard libraries. + std::istringstream input(s); + input.imbue(std::locale(setlocale(LC_ALL, nullptr))); + input >> std::get_time(tm, f); + if (input.fail()) { + return nullptr; + } + return (char*)(s + input.tellg()); +} +#endif #include #include