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

osm_opening_hours.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e808420dac63f2dd59d98344dfbbad1cf9b512d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include "3party/opening_hours/osm_time_range.hpp"

#include "std/chrono.hpp"

namespace osm
{
enum class EPlaceState
{
  Open,
  Closed,
  OpenSoon,
  CloseSoon
};

inline string DebugPrint(EPlaceState state)
{
  switch (state)
  {
    case EPlaceState::Open:
      return "EPlaceState::Open";
    case EPlaceState::OpenSoon:
      return "EPlaceState::OpenSoon";
    case EPlaceState::Closed:
      return "EPlaceState::Closed";
    case EPlaceState::CloseSoon:
      return "EPlaceState::CloseSoon";
  }
}

inline 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