diff options
author | Sergey Magidovich <mgsergio@mapswithme.com> | 2015-12-22 11:26:12 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:04:01 +0300 |
commit | 832abf1f54c1466e7d547e7c9eaab4eb03c71d29 (patch) | |
tree | a7881bc7ad9a06b546cab9bbb981ef7535e9de0c /3party | |
parent | db00bcfdee2da905c7d0ba8b00495f78e1fd3ba3 (diff) |
Implement from OpeningHours to TimeTableSet conversion.
Diffstat (limited to '3party')
-rw-r--r-- | 3party/opening_hours/opening_hours.cpp | 26 | ||||
-rw-r--r-- | 3party/opening_hours/opening_hours.hpp | 17 | ||||
-rw-r--r-- | 3party/opening_hours/rules_evaluation.cpp | 2 |
3 files changed, 45 insertions, 0 deletions
diff --git a/3party/opening_hours/opening_hours.cpp b/3party/opening_hours/opening_hours.cpp index 342a339153..e847d45615 100644 --- a/3party/opening_hours/opening_hours.cpp +++ b/3party/opening_hours/opening_hours.cpp @@ -26,7 +26,9 @@ #include "rules_evaluation.hpp" #include "parse_opening_hours.hpp" +#include <algorithm> #include <cstdlib> +#include <functional> #include <iomanip> #include <ios> #include <ostream> @@ -748,4 +750,28 @@ bool OpeningHours::IsValid() const { return m_valid; } +bool OpeningHours::IsTwentyFourHours() const +{ + return m_rule.size() == 1 && m_rule[0].IsTwentyFourHours(); +} + +bool OpeningHours::HasWeekdaySelector() const +{ + return std::any_of(begin(m_rule), end(m_rule), std::mem_fn(&osmoh::RuleSequence::HasWeekdays)); +} + +bool OpeningHours::HasMonthSelector() const +{ + return std::any_of(begin(m_rule), end(m_rule), std::mem_fn(&osmoh::RuleSequence::HasMonths)); +} + +bool OpeningHours::HasWeekSelector() const +{ + return std::any_of(begin(m_rule), end(m_rule), std::mem_fn(&osmoh::RuleSequence::HasWeeks)); +} + +bool OpeningHours::HasYearSelector() const +{ + return std::any_of(begin(m_rule), end(m_rule), std::mem_fn(&osmoh::RuleSequence::HasYears)); +} } // namespace osmoh diff --git a/3party/opening_hours/opening_hours.hpp b/3party/opening_hours/opening_hours.hpp index 31594695f4..d9f229f80b 100644 --- a/3party/opening_hours/opening_hours.hpp +++ b/3party/opening_hours/opening_hours.hpp @@ -69,6 +69,16 @@ private: HourMinutes operator-(HourMinutes const & hm); std::ostream & operator<<(std::ostream & ost, HourMinutes const & hm); +inline bool operator<(HourMinutes const & a, HourMinutes const & b) +{ + return a.GetDuration() < b.GetDuration(); +} + +inline bool operator==(HourMinutes const & a, HourMinutes const & b) +{ + return a.GetDuration() == b.GetDuration(); +} + class Time; class TimeEvent @@ -661,6 +671,13 @@ public: bool IsValid() const; + bool IsTwentyFourHours() const; + bool HasWeekdaySelector() const; + bool HasMonthSelector() const; + bool HasWeekSelector() const; + bool HasYearSelector() const; + + TRuleSequences const & GetRule() const { return m_rule; } private: TRuleSequences m_rule; bool const m_valid; diff --git a/3party/opening_hours/rules_evaluation.cpp b/3party/opening_hours/rules_evaluation.cpp index 8f951195e4..1ea5490e73 100644 --- a/3party/opening_hours/rules_evaluation.cpp +++ b/3party/opening_hours/rules_evaluation.cpp @@ -196,6 +196,8 @@ std::tm MakeTimetuple(time_t const timestamp) namespace osmoh { +using ::operator==; + bool IsActive(Timespan const & span, std::tm const & time) { // Timespan with e.h. should be split into parts with no e.h. |