diff --git a/wxdata/include/scwx/gr/placefile.hpp b/wxdata/include/scwx/gr/placefile.hpp index 81b37daa..671af535 100644 --- a/wxdata/include/scwx/gr/placefile.hpp +++ b/wxdata/include/scwx/gr/placefile.hpp @@ -71,8 +71,10 @@ public: struct DrawItem { - ItemType itemType_ {ItemType::Unknown}; - units::length::nautical_miles threshold_ {}; + ItemType itemType_ {ItemType::Unknown}; + units::length::nautical_miles threshold_ {}; + std::chrono::sys_time startTime_ {}; + std::chrono::sys_time endTime_ {}; }; struct IconDrawItem : DrawItem diff --git a/wxdata/source/scwx/gr/placefile.cpp b/wxdata/source/scwx/gr/placefile.cpp index 5d007647..8ef9ba2d 100644 --- a/wxdata/source/scwx/gr/placefile.cpp +++ b/wxdata/source/scwx/gr/placefile.cpp @@ -1,3 +1,8 @@ +// Enable chrono formatters +#ifndef __cpp_lib_format +# define __cpp_lib_format 202110L +#endif + #include #include #include @@ -10,6 +15,10 @@ #include +#if !defined(_MSC_VER) +# include +#endif + using namespace units::literals; namespace scwx @@ -59,10 +68,13 @@ public: std::chrono::seconds refresh_ {-1}; // Parsing state - units::length::nautical_miles threshold_ {999.0_nmi}; - boost::gil::rgba8_pixel_t color_ {255, 255, 255, 255}; - ColorMode colorMode_ {ColorMode::RGBA}; - std::vector objectStack_ {}; + units::length::nautical_miles threshold_ {999.0_nmi}; + boost::gil::rgba8_pixel_t color_ {255, 255, 255, 255}; + ColorMode colorMode_ {ColorMode::RGBA}; + std::chrono::sys_time startTime_ {}; + std::chrono::sys_time endTime_ {}; + + std::vector objectStack_ {}; DrawingStatement currentStatement_ {DrawingStatement::Standard}; std::shared_ptr currentDrawItem_ {nullptr}; std::vector currentPolygonContour_ {}; @@ -256,8 +268,46 @@ void Placefile::Impl::ProcessLine(const std::string& line) else if (boost::istarts_with(line, timeRangeKey_)) { // TimeRange: start_time end_time + // (YYYY-MM-DDThh:mm:ss) + std::vector tokenList = + util::ParseTokens(line, {" ", " "}, timeRangeKey_.size()); - // TODO + if (tokenList.size() >= 2) + { + using namespace std::chrono; + +#if !defined(_MSC_VER) + using namespace date; +#endif + + static const std::string dateTimeFormat {"%Y-%m-%dT%H:%M:%S"}; + + std::istringstream ssStartTime {tokenList[0]}; + std::istringstream ssEndTime {tokenList[1]}; + + std::chrono::sys_time startTime; + std::chrono::sys_time endTime; + + ssStartTime >> parse(dateTimeFormat, startTime); + ssEndTime >> parse(dateTimeFormat, endTime); + + if (!ssStartTime.fail() && !ssEndTime.fail()) + { + startTime_ = startTime; + endTime_ = endTime; + } + else + { + startTime_ = {}; + endTime_ = {}; + + logger_->warn("TimeRange statement parse error: {}", line); + } + } + else + { + logger_->warn("TimeRange statement malformed: {}", line); + } } else if (boost::istarts_with(line, hsluvKey_)) { @@ -322,6 +372,8 @@ void Placefile::Impl::ProcessLine(const std::string& line) di->threshold_ = threshold_; di->color_ = color_; + di->startTime_ = startTime_; + di->endTime_ = endTime_; ParseLocation(tokenList[0], tokenList[1], @@ -379,6 +431,8 @@ void Placefile::Impl::ProcessLine(const std::string& line) di = std::make_shared(); di->threshold_ = threshold_; + di->startTime_ = startTime_; + di->endTime_ = endTime_; ParseLocation(tokenList[0], tokenList[1], @@ -446,6 +500,8 @@ void Placefile::Impl::ProcessLine(const std::string& line) di->threshold_ = threshold_; di->color_ = color_; + di->startTime_ = startTime_; + di->endTime_ = endTime_; ParseLocation(tokenList[0], tokenList[1], @@ -526,6 +582,8 @@ void Placefile::Impl::ProcessLine(const std::string& line) di->threshold_ = threshold_; di->color_ = color_; + di->startTime_ = startTime_; + di->endTime_ = endTime_; di->width_ = std::stoul(tokenList[0]); di->flags_ = std::stoul(tokenList[1]); @@ -560,6 +618,8 @@ void Placefile::Impl::ProcessLine(const std::string& line) di->threshold_ = threshold_; di->color_ = color_; + di->startTime_ = startTime_; + di->endTime_ = endTime_; currentDrawItem_ = di; drawItems_.emplace_back(std::move(di)); @@ -582,6 +642,8 @@ void Placefile::Impl::ProcessLine(const std::string& line) di = std::make_shared(); di->threshold_ = threshold_; + di->startTime_ = startTime_; + di->endTime_ = endTime_; TrimQuotes(tokenList[0]); di->imageFile_.swap(tokenList[0]); @@ -612,6 +674,8 @@ void Placefile::Impl::ProcessLine(const std::string& line) di->threshold_ = threshold_; di->color_ = color_; + di->startTime_ = startTime_; + di->endTime_ = endTime_; currentDrawItem_ = di; drawItems_.emplace_back(std::move(di));