diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e0f6ed..99d73d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ find_package(nlohmann_json REQUIRED) find_package(OpenSSL REQUIRED) find_package(CURL REQUIRED) find_package(PkgConfig REQUIRED) +find_package(date REQUIRED) pkg_check_modules(LIBSECRET REQUIRED libsecret-1) add_library(launchpad SHARED @@ -78,5 +79,6 @@ target_link_libraries(launchpad PRIVATE nlohmann_json::nlohmann_json OpenSSL::Crypto CURL::libcurl + date::date-tz ${LIBSECRET_LIBRARIES} ) diff --git a/src/build.cpp b/src/build.cpp index 47a3433..db48afb 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -17,6 +17,7 @@ #include "source_package_publishing_history.h" #include "utils.h" #include "launchpad.h" +#include #include #include #include @@ -66,48 +67,48 @@ void build::parse_json(const std::string& json_data) { {"external_dependencies", [this](const nlohmann::json& val) { external_dependencies = val.get(); }}, {"pocket", [this](const nlohmann::json& val) { pocket = val.get(); }}, {"date_first_dispatched", [this](const nlohmann::json& val) { - std::string datetimeStr = val.get(); - std::istringstream ss(datetimeStr); - std::tm tm = {}; - ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z"); + std::chrono::sys_time parsed_time; + std::istringstream ss(val.get()); + ss >> date::parse("%FT%T%z", parsed_time); + if (ss.fail()) { - std::cout << val << std::endl; - throw std::runtime_error("Failed to parse date_first_dispatched"); + throw std::runtime_error("Failed to parse date_first_dispatched: " + val.get()); } - date_first_dispatched = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + + date_first_dispatched = std::chrono::time_point_cast(parsed_time); }}, {"date_started", [this](const nlohmann::json& val) { - std::string datetimeStr = val.get(); - std::istringstream ss(datetimeStr); - std::tm tm = {}; - ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z"); + std::chrono::sys_time parsed_time; + std::istringstream ss(val.get()); + ss >> date::parse("%FT%T%z", parsed_time); + if (ss.fail()) { - std::cout << val << std::endl; - throw std::runtime_error("Failed to parse date_started"); + throw std::runtime_error("Failed to parse date_started: " + val.get()); } - date_started = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + + date_started = std::chrono::time_point_cast(parsed_time); }}, {"datebuilt", [this](const nlohmann::json& val) { - std::string datetimeStr = val.get(); - std::istringstream ss(datetimeStr); - std::tm tm = {}; - ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z"); + std::chrono::sys_time parsed_time; + std::istringstream ss(val.get()); + ss >> date::parse("%FT%T%z", parsed_time); + if (ss.fail()) { - std::cout << val << std::endl; - throw std::runtime_error("Failed to parse datebuilt"); + throw std::runtime_error("Failed to parse datebuilt: " + val.get()); } - datebuilt = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + + datebuilt = std::chrono::time_point_cast(parsed_time); }}, {"datecreated", [this](const nlohmann::json& val) { - std::string datetimeStr = val.get(); - std::istringstream ss(datetimeStr); - std::tm tm = {}; - ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z"); + std::chrono::sys_time parsed_time; + std::istringstream ss(val.get()); + ss >> date::parse("%FT%T%z", parsed_time); + if (ss.fail()) { - std::cout << val << std::endl; - throw std::runtime_error("Failed to parse datecreated"); + throw std::runtime_error("Failed to parse datecreated: " + val.get()); } - datecreated = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + + datecreated = std::chrono::time_point_cast(parsed_time); }} };