diff --git a/src/build.cpp b/src/build.cpp index 56912eb..278e401 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -64,7 +64,51 @@ void build::parse_json(const std::string& json_data) { {"changesfile_url", [this](const nlohmann::json& val) { changesfile_url = val.get(); }}, {"buildinfo_url", [this](const nlohmann::json& val) { buildinfo_url = val.get(); }}, {"external_dependencies", [this](const nlohmann::json& val) { external_dependencies = val.get(); }}, - {"pocket", [this](const nlohmann::json& val) { pocket = 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"); + if (ss.fail()) { + std::cout << val << std::endl; + throw std::runtime_error("Failed to parse date_first_dispatched"); + } + date_first_dispatched = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + }}, + {"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"); + if (ss.fail()) { + std::cout << val << std::endl; + throw std::runtime_error("Failed to parse date_started"); + } + date_started = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + }}, + {"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"); + if (ss.fail()) { + std::cout << val << std::endl; + throw std::runtime_error("Failed to parse datebuilt"); + } + datebuilt = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + }}, + {"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"); + if (ss.fail()) { + std::cout << val << std::endl; + throw std::runtime_error("Failed to parse datecreated"); + } + datecreated = std::chrono::system_clock::from_time_t(std::mktime(&tm)); + }} }; // Process JSON keys diff --git a/src/build.h b/src/build.h index 25fc2ea..e8b30c4 100644 --- a/src/build.h +++ b/src/build.h @@ -74,10 +74,10 @@ public: std::string source_package_name; std::string source_package_version; std::string web_link; - std::string date_first_dispatched; - std::string date_started; - std::string datebuilt; - std::string datecreated; + std::chrono::system_clock::time_point date_first_dispatched; + std::chrono::system_clock::time_point date_started; + std::chrono::system_clock::time_point datebuilt; + std::chrono::system_clock::time_point datecreated; // Object collections std::optional current_source_publication = getCurrentSourcePublication();