From de8d7a812c4da9f0375dc47626c0e836ba728207 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 21 May 2022 00:26:44 +0200 Subject: Find start and end dates in Reader --- Reader.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Reader.cpp b/Reader.cpp index 07cb175..f14b837 100644 --- a/Reader.cpp +++ b/Reader.cpp @@ -1,6 +1,8 @@ #include "Reader.h" +#include #include +#include #include "Grid.h" #include "LongVector3.h" @@ -14,13 +16,19 @@ static constexpr long double EXTENT {1000 * 50000}; static Grid& find_grid_for(std::vector& grids, const LongVector3& position); +static std::tm end_of_time(); +static bool earlier(const std::tm& lhs, const std::tm& rhs); std::vector Reader::read(Source& source) { std::vector grids; + std::tm start = end_of_time(); + std::tm end = {}; for (auto& km : source.killmails()) { + if (earlier(km.time, start)) start = km.time; + if (earlier(end, km.time)) end = km.time; auto& grid = find_grid_for(grids, km.position); grid.wrecks.push_back(Wreck{Vector3{0, 0, 0}, km}); } @@ -44,6 +52,8 @@ Reader::read(Source& source) } grid.origin = average; } + (void) start; + (void) end; return grids; } @@ -58,3 +68,36 @@ find_grid_for(std::vector& grids, const LongVector3& position) grids.push_back(Grid{}); return grids.back(); } + + +std::tm +end_of_time() +{ + std::tm time {}; + time.tm_sec = 60; + time.tm_min = 59; + time.tm_hour = 23; + time.tm_mday = 31; + time.tm_mon = 11; + time.tm_year = std::numeric_limits::max(); + return time; +} + + +bool +earlier(const std::tm& lhs, const std::tm& rhs) +{ + if (lhs.tm_year > rhs.tm_year) return false; + if (lhs.tm_year < rhs.tm_year) return true; + if (lhs.tm_mon > rhs.tm_mon) return false; + if (lhs.tm_mon < rhs.tm_mon) return true; + if (lhs.tm_mday > rhs.tm_mday) return false; + if (lhs.tm_mday < rhs.tm_mday) return true; + if (lhs.tm_hour > rhs.tm_hour) return false; + if (lhs.tm_hour < rhs.tm_hour) return true; + if (lhs.tm_min > rhs.tm_min) return false; + if (lhs.tm_min < rhs.tm_min) return true; + if (lhs.tm_sec > rhs.tm_sec) return false; + if (lhs.tm_sec < rhs.tm_sec) return true; + return false; +} -- cgit v1.1