Fix datetime objects

main
Simon Quigley 6 days ago
parent a2a993d713
commit 7879ec07be

@ -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}
)

@ -17,6 +17,7 @@
#include "source_package_publishing_history.h"
#include "utils.h"
#include "launchpad.h"
#include <date/date.h>
#include <iostream>
#include <nlohmann/json.hpp>
#include <regex>
@ -66,48 +67,48 @@ void build::parse_json(const std::string& json_data) {
{"external_dependencies", [this](const nlohmann::json& val) { external_dependencies = val.get<std::string>(); }},
{"pocket", [this](const nlohmann::json& val) { pocket = val.get<std::string>(); }},
{"date_first_dispatched", [this](const nlohmann::json& val) {
std::string datetimeStr = val.get<std::string>();
std::istringstream ss(datetimeStr);
std::tm tm = {};
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z");
std::chrono::sys_time<std::chrono::microseconds> parsed_time;
std::istringstream ss(val.get<std::string>());
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<std::string>());
}
date_first_dispatched = std::chrono::system_clock::from_time_t(std::mktime(&tm));
date_first_dispatched = std::chrono::time_point_cast<std::chrono::system_clock::duration>(parsed_time);
}},
{"date_started", [this](const nlohmann::json& val) {
std::string datetimeStr = val.get<std::string>();
std::istringstream ss(datetimeStr);
std::tm tm = {};
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z");
std::chrono::sys_time<std::chrono::microseconds> parsed_time;
std::istringstream ss(val.get<std::string>());
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<std::string>());
}
date_started = std::chrono::system_clock::from_time_t(std::mktime(&tm));
date_started = std::chrono::time_point_cast<std::chrono::system_clock::duration>(parsed_time);
}},
{"datebuilt", [this](const nlohmann::json& val) {
std::string datetimeStr = val.get<std::string>();
std::istringstream ss(datetimeStr);
std::tm tm = {};
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z");
std::chrono::sys_time<std::chrono::microseconds> parsed_time;
std::istringstream ss(val.get<std::string>());
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<std::string>());
}
datebuilt = std::chrono::system_clock::from_time_t(std::mktime(&tm));
datebuilt = std::chrono::time_point_cast<std::chrono::system_clock::duration>(parsed_time);
}},
{"datecreated", [this](const nlohmann::json& val) {
std::string datetimeStr = val.get<std::string>();
std::istringstream ss(datetimeStr);
std::tm tm = {};
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S.%f%z");
std::chrono::sys_time<std::chrono::microseconds> parsed_time;
std::istringstream ss(val.get<std::string>());
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<std::string>());
}
datecreated = std::chrono::system_clock::from_time_t(std::mktime(&tm));
datecreated = std::chrono::time_point_cast<std::chrono::system_clock::duration>(parsed_time);
}}
};

Loading…
Cancel
Save