Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Yershov <yershov@corp.mail.ru>2015-06-09 15:46:10 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:50:25 +0300
commit99e67965908a321213a76794095877b6f303ef29 (patch)
tree928840b861225df6423b340dea0efa294b0bd901
parent3c1de6f1294c1449494b26e0036e62b048d7356c (diff)
Check open soon and close soon cases
-rw-r--r--map/map_tests/working_time_tests.cpp62
-rw-r--r--map/osm_opening_hours.hpp45
-rw-r--r--std/chrono.hpp1
3 files changed, 108 insertions, 0 deletions
diff --git a/map/map_tests/working_time_tests.cpp b/map/map_tests/working_time_tests.cpp
new file mode 100644
index 0000000000..686136cc0d
--- /dev/null
+++ b/map/map_tests/working_time_tests.cpp
@@ -0,0 +1,62 @@
+#include "testing/testing.hpp"
+
+#include "map/osm_opening_hours.hpp"
+
+using namespace osm;
+
+UNIT_TEST(OpenSoon)
+{
+ // 1-jan-2000 08:50
+ std::tm when = {};
+ when.tm_mday = 1;
+ when.tm_mon = 0;
+ when.tm_year = 100;
+ when.tm_hour = 8;
+ when.tm_min = 50;
+
+ time_t now = std::mktime(&when);
+
+ TEST_EQUAL(PlaceStateCheck("09:00-21:00", now), EPlaceState::OpenSoon, ());
+}
+
+UNIT_TEST(CloseSoon)
+{
+ // 1-jan-2000 20:50
+ std::tm when = {};
+ when.tm_mday = 1;
+ when.tm_mon = 0;
+ when.tm_year = 100;
+ when.tm_hour = 20;
+ when.tm_min = 50;
+
+ time_t now = std::mktime(&when);
+ TEST_EQUAL(PlaceStateCheck("09:00-21:00", now), EPlaceState::CloseSoon, ());
+}
+
+UNIT_TEST(Open)
+{
+ // 1-jan-2000 13:50
+ std::tm when = {};
+ when.tm_mday = 1;
+ when.tm_mon = 0;
+ when.tm_year = 100;
+ when.tm_hour = 13;
+ when.tm_min = 50;
+
+ time_t now = std::mktime(&when);
+ TEST_EQUAL(PlaceStateCheck("09:00-21:00", now), EPlaceState::Open, ());
+}
+
+UNIT_TEST(Closed)
+{
+ // 1-jan-2000 06:50
+ std::tm when = {};
+ when.tm_mday = 1;
+ when.tm_mon = 0;
+ when.tm_year = 100;
+ when.tm_hour = 6;
+ when.tm_min = 50;
+
+ time_t now = std::mktime(&when);
+ TEST_EQUAL(PlaceStateCheck("09:00-21:00", now), EPlaceState::Closed, ());
+}
diff --git a/map/osm_opening_hours.hpp b/map/osm_opening_hours.hpp
new file mode 100644
index 0000000000..fb0075a055
--- /dev/null
+++ b/map/osm_opening_hours.hpp
@@ -0,0 +1,45 @@
+#pragma once
+
+#include "3party/opening_hours/osm_time_range.hpp"
+
+#include "std/chrono.hpp"
+
+namespace osm
+{
+enum class EPlaceState
+{
+ Open,
+ Closed,
+ OpenSoon,
+ CloseSoon
+};
+
+ostream & operator<<(ostream & s, EPlaceState state)
+{
+ switch (state)
+ {
+ case EPlaceState::Open:
+ return s << "Open";
+ case EPlaceState::OpenSoon:
+ return s << "Open soon";
+ case EPlaceState::Closed:
+ return s << "Closed";
+ case EPlaceState::CloseSoon:
+ return s << "Close soon";
+ }
+}
+
+EPlaceState PlaceStateCheck(string const & openingHours, time_t timestamp)
+{
+ OSMTimeRange oh(openingHours);
+ auto future = system_clock::from_time_t(timestamp);
+ future += minutes(15);
+ size_t nowState = oh(timestamp).IsOpen() ? 0 : 1;
+ size_t futureState = oh(system_clock::to_time_t(future)).IsOpen() ? 0 : 1;
+
+ EPlaceState state[2][2] = {{EPlaceState::Open, EPlaceState::CloseSoon},
+ {EPlaceState::OpenSoon, EPlaceState::Closed}};
+
+ return state[nowState][futureState];
+}
+} // namespace osm
diff --git a/std/chrono.hpp b/std/chrono.hpp
index 3ff3eb12c2..bae8000f67 100644
--- a/std/chrono.hpp
+++ b/std/chrono.hpp
@@ -11,6 +11,7 @@ using std::chrono::duration_cast;
using std::chrono::high_resolution_clock;
using std::chrono::milliseconds;
using std::chrono::nanoseconds;
+using std::chrono::minutes;
using std::chrono::steady_clock;
using std::chrono::system_clock;