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
path: root/3party
diff options
context:
space:
mode:
authorSergey Magidovich <mgsergio@mapswithme.com>2015-12-22 17:51:26 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:04:03 +0300
commit54bcbe2b3dc185d991f291b3a9f0f391b7131c11 (patch)
tree8527aeda8b722672ce013f590fb6c73735f560e6 /3party
parent8c08017809990f335e404394537c79cbc830bf02 (diff)
Fix bugs in WeekdayRange::HasWday. Add ConvertOpeningHours(string, TimeTableSet &).
Diffstat (limited to '3party')
-rw-r--r--3party/opening_hours/opening_hours.cpp7
-rw-r--r--3party/opening_hours/opening_hours.hpp2
-rw-r--r--3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp12
-rw-r--r--3party/opening_hours/rules_evaluation.cpp14
4 files changed, 18 insertions, 17 deletions
diff --git a/3party/opening_hours/opening_hours.cpp b/3party/opening_hours/opening_hours.cpp
index e847d45615..0adc164e1c 100644
--- a/3party/opening_hours/opening_hours.cpp
+++ b/3party/opening_hours/opening_hours.cpp
@@ -335,7 +335,7 @@ std::ostream & operator<<(std::ostream & ost, NthWeekdayOfTheMonthEntry const en
}
// WeekdayRange ------------------------------------------------------------------------------------
-bool WeekdayRange::HasWday(Weekday const & wday) const
+bool WeekdayRange::HasWday(Weekday const wday) const
{
if (IsEmpty() || wday == Weekday::None)
return false;
@@ -343,10 +343,11 @@ bool WeekdayRange::HasWday(Weekday const & wday) const
if (!HasEnd())
return GetStart() == wday;
- return GetStart() <= wday && wday <= GetEnd();
+ return (GetStart() <= GetEnd())
+ ? GetStart() <= wday && wday <= GetEnd()
+ : wday >= GetEnd() || GetStart() <= wday;
}
-
std::ostream & operator<<(std::ostream & ost, Weekday const wday)
{
switch (wday)
diff --git a/3party/opening_hours/opening_hours.hpp b/3party/opening_hours/opening_hours.hpp
index d9f229f80b..20f17d86ce 100644
--- a/3party/opening_hours/opening_hours.hpp
+++ b/3party/opening_hours/opening_hours.hpp
@@ -306,7 +306,7 @@ class WeekdayRange
using TNths = std::vector<NthWeekdayOfTheMonthEntry>;
public:
- bool HasWday(Weekday const & wday) const;
+ bool HasWday(Weekday const wday) const;
bool HasSunday() const { return HasWday(Weekday::Sunday); }
bool HasMonday() const { return HasWday(Weekday::Monday); }
diff --git a/3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp b/3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp
index d86ff88e91..8098a35a1e 100644
--- a/3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp
+++ b/3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp
@@ -392,7 +392,19 @@ BOOST_AUTO_TEST_CASE(OpeningHours_TestWeekdayRange)
range.AddNth(entry);
BOOST_CHECK(range.HasNth());
}
+ {
+ WeekdayRange range;
+ range.SetStart(Weekday::Monday);
+ range.SetEnd(Weekday::Sunday);
+ BOOST_CHECK(range.HasSunday());
+ BOOST_CHECK(range.HasMonday());
+ BOOST_CHECK(range.HasTuesday());
+ BOOST_CHECK(range.HasWednesday());
+ BOOST_CHECK(range.HasThursday());
+ BOOST_CHECK(range.HasFriday());
+ BOOST_CHECK(range.HasSaturday());
+ }
}
BOOST_AUTO_TEST_CASE(OpeningHours_Holidays)
diff --git a/3party/opening_hours/rules_evaluation.cpp b/3party/opening_hours/rules_evaluation.cpp
index ea266c7e3d..3762b8360d 100644
--- a/3party/opening_hours/rules_evaluation.cpp
+++ b/3party/opening_hours/rules_evaluation.cpp
@@ -93,15 +93,6 @@ uint8_t GetWeekNumber(std::tm const & date)
return weekNumber;
}
-bool IsBetweenLooped(osmoh::Weekday const start,
- osmoh::Weekday const end,
- osmoh::Weekday const p)
-{
- if (start <= end)
- return start <= p && p <= end;
- return p >= end || start <= p;
-}
-
osmoh::RuleState ModifierToRuleState(osmoh::RuleSequence::Modifier const modifier)
{
using Modifier = osmoh::RuleSequence::Modifier;
@@ -239,10 +230,7 @@ bool IsActive(WeekdayRange const & range, std::tm const & date)
if (wday == Weekday::None)
return false;
- if (range.HasEnd())
- return IsBetweenLooped(range.GetStart(), range.GetEnd(), wday);
-
- return range.GetStart() == wday;
+ return range.HasWday(wday);
}
bool IsActive(Holiday const & holiday, std::tm const & date)