diff options
author | Sergey Yershov <yershov@corp.mail.ru> | 2015-06-09 15:46:10 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:50:25 +0300 |
commit | 99e67965908a321213a76794095877b6f303ef29 (patch) | |
tree | 928840b861225df6423b340dea0efa294b0bd901 /map/osm_opening_hours.hpp | |
parent | 3c1de6f1294c1449494b26e0036e62b048d7356c (diff) |
Check open soon and close soon cases
Diffstat (limited to 'map/osm_opening_hours.hpp')
-rw-r--r-- | map/osm_opening_hours.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
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 |