summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-21 00:26:44 +0200
committerAki <please@ignore.pl>2022-05-21 00:30:05 +0200
commitde8d7a812c4da9f0375dc47626c0e836ba728207 (patch)
tree80596e335b7f816f79b7554b868b977d792e72ba
parent0e0358af887336d3466ac408e0404fbc806611f0 (diff)
downloadderelict-de8d7a812c4da9f0375dc47626c0e836ba728207.zip
derelict-de8d7a812c4da9f0375dc47626c0e836ba728207.tar.gz
derelict-de8d7a812c4da9f0375dc47626c0e836ba728207.tar.bz2
Find start and end dates in Reader
-rw-r--r--Reader.cpp43
1 files changed, 43 insertions, 0 deletions
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 <ctime>
#include <vector>
+#include <limits>
#include "Grid.h"
#include "LongVector3.h"
@@ -14,13 +16,19 @@ static constexpr long double EXTENT {1000 * 50000};
static Grid& find_grid_for(std::vector<Grid>& grids, const LongVector3& position);
+static std::tm end_of_time();
+static bool earlier(const std::tm& lhs, const std::tm& rhs);
std::vector<Grid>
Reader::read(Source& source)
{
std::vector<Grid> 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<Grid>& 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<decltype(time.tm_year)>::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;
+}