From 02475e05ccd1aa15c6a6163834f28bfebbef796f Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Mon, 30 Nov 2026 11:47:36 +0100 Subject: RWGPS webhook and such --- server/src/datex2.cpp | 63 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 24 deletions(-) (limited to 'server/src/datex2.cpp') diff --git a/server/src/datex2.cpp b/server/src/datex2.cpp index 70c5f94..ab49fd9 100644 --- a/server/src/datex2.cpp +++ b/server/src/datex2.cpp @@ -14,11 +14,11 @@ using namespace std::literals::string_view_literals; namespace routemon::datex2 { -auto parse_timestamp(char const* in) -> std::optional +auto parse_timestamp_secs(char const* in) -> std::optional> { - auto res = time::timestamp{}; + auto res = time::timestamp<>{}; auto is = std::istringstream{in}; - is >> std::chrono::parse("%Y-%m-%dT%H:%M:%SZ", res); + is >> std::chrono::parse("%FT%TZ", res); return is.fail() ? std::nullopt : std::make_optional(res); } @@ -178,7 +178,7 @@ auto loader::handle_road_or_carriageway_or_lane_management( //---- Check if within the defined validity period - auto validity = std::optional{}; + auto validity = std::optional>{}; auto const& validity_xml = record_xml.child("sit:validity"); if (validity_xml && validity_xml.child_value("com:validityStatus") @@ -187,52 +187,67 @@ auto loader::handle_road_or_carriageway_or_lane_management( auto const& validity_spec_xml = validity_xml.child("com:validityTimeSpecification"); - auto valid_periods = std::vector{}; - auto exception_periods = std::vector{}; + auto valid_periods = std::vector>{}; + auto exception_periods = std::vector>{}; // TODO: com:overallEndTime may be missing (according to the DATEX // II v3 data model) - auto const overall_start_time = - parse_timestamp(validity_spec_xml.child_value("com:overallStartTime")); - auto const overall_end_time = - parse_timestamp(validity_spec_xml.child_value("com:overallEndTime")); + auto const overall_start_time = parse_timestamp_secs( + validity_spec_xml.child_value("com:overallStartTime")); + auto const overall_end_time = parse_timestamp_secs( + validity_spec_xml.child_value("com:overallEndTime")); if (overall_start_time && overall_end_time && *overall_start_time < *overall_end_time) { - valid_periods.emplace_back(*overall_start_time, *overall_end_time); + valid_periods.emplace_back( + std::chrono::time_point_cast( + *overall_start_time), + std::chrono::time_point_cast( + *overall_end_time)); for (auto const valid_period_xml : validity_xml.children("com:validPeriod")) { - auto const start_of_period = - parse_timestamp(valid_period_xml.child_value("com:startOfPeriod")); - auto const end_of_period = - parse_timestamp(valid_period_xml.child_value("com:endOfPeriod")); + auto const start_of_period = parse_timestamp_secs( + valid_period_xml.child_value("com:startOfPeriod")); + auto const end_of_period = parse_timestamp_secs( + valid_period_xml.child_value("com:endOfPeriod")); if (start_of_period && end_of_period && *start_of_period < *end_of_period) { - valid_periods.emplace_back(*start_of_period, *end_of_period); + valid_periods.emplace_back( + std::chrono::time_point_cast( + *start_of_period), + std::chrono::time_point_cast( + *end_of_period)); } } for (auto const exception_period_xml : validity_xml.children("com:exceptionPeriod")) { - auto const start_of_period = parse_timestamp( + auto const start_of_period = parse_timestamp_secs( exception_period_xml.child_value("com:startOfPeriod")); - auto const end_of_period = parse_timestamp( + auto const end_of_period = parse_timestamp_secs( exception_period_xml.child_value("com:endOfPeriod")); if (start_of_period && end_of_period && *start_of_period < *end_of_period) { - exception_periods.emplace_back(*start_of_period, *end_of_period); + exception_periods.emplace_back( + std::chrono::time_point_cast( + *start_of_period), + std::chrono::time_point_cast( + *end_of_period)); } } validity = - time::period_seq{valid_periods.begin(), valid_periods.end()}.except( - time::period_seq{ - exception_periods.begin(), exception_periods.end() - }); + time::period_seq{ + valid_periods.begin(), valid_periods.end() + } + .except( + time::period_seq{ + exception_periods.begin(), exception_periods.end() + }); } else { @@ -263,7 +278,7 @@ auto loader::load_situation_publication(std::string const& filename) } auto payload_xml = doc.child("mc:messageContainer").child("mc:payload"); auto mpublication_time = - parse_timestamp(payload_xml.child_value("com:publicationTime")); + parse_timestamp_secs(payload_xml.child_value("com:publicationTime")); if (!mpublication_time) throw std::runtime_error{ "provided publication does not name publication time" -- cgit v1.3.1