From f59fb509c91d771112973754b0514c1529b70b8e Mon Sep 17 00:00:00 2001 From: Harry Bond Date: Tue, 17 Jun 2025 16:49:22 +0100 Subject: [PATCH] [core] Remove legacy opening_hours stuff Signed-off-by: Harry Bond --- map/map_tests/CMakeLists.txt | 1 - map/map_tests/working_time_tests.cpp | 62 ---------------------------- map/osm_opening_hours.hpp | 62 ---------------------------- 3 files changed, 125 deletions(-) delete mode 100644 map/map_tests/working_time_tests.cpp delete mode 100644 map/osm_opening_hours.hpp diff --git a/map/map_tests/CMakeLists.txt b/map/map_tests/CMakeLists.txt index fcfc0b46f..88570bdbc 100644 --- a/map/map_tests/CMakeLists.txt +++ b/map/map_tests/CMakeLists.txt @@ -16,7 +16,6 @@ set(SRC power_manager_tests.cpp search_api_tests.cpp transliteration_test.cpp - working_time_tests.cpp elevation_info_tests.cpp track_statistics_tests.cpp ) diff --git a/map/map_tests/working_time_tests.cpp b/map/map_tests/working_time_tests.cpp deleted file mode 100644 index d827e1475..000000000 --- a/map/map_tests/working_time_tests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "testing/testing.hpp" - -#include "map/osm_opening_hours.hpp" - -using namespace osm; - -UNIT_TEST(WorkingTime_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(WorkingTime_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(WorkingTime_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(WorkingTime_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 deleted file mode 100644 index fb2809595..000000000 --- a/map/osm_opening_hours.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include "3party/opening_hours/opening_hours.hpp" - -#include "base/assert.hpp" - -#include -#include -#include - -namespace osm -{ -enum class EPlaceState -{ - Open, - Closed, - OpenSoon, - CloseSoon -}; - -inline std::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"; - } - UNREACHABLE(); -} - -inline EPlaceState PlaceStateCheck(std::string const & openingHours, time_t timestamp) -{ - osmoh::OpeningHours oh(openingHours); - - auto future = std::chrono::system_clock::from_time_t(timestamp); - future += std::chrono::minutes(15); - - enum {OPEN = 0, CLOSED = 1}; - - size_t nowState = OPEN; - size_t futureState = OPEN; - - // TODO(mgsergio): Switch to three-stated model instead of two-staed - // I.e. set unknown if we can't parse or can't answer whether it's open. - if (oh.IsValid()) - { - nowState = oh.IsOpen(timestamp) ? OPEN : CLOSED; - futureState = oh.IsOpen(std::chrono::system_clock::to_time_t(future)) ? OPEN : CLOSED; - } - - EPlaceState state[2][2] = {{EPlaceState::Open, EPlaceState::CloseSoon}, - {EPlaceState::OpenSoon, EPlaceState::Closed}}; - - return state[nowState][futureState]; -} -} // namespace osm