diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-07-24 17:34:32 +0300 |
---|---|---|
committer | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-07-24 17:34:32 +0300 |
commit | 121db552b0a4f7c8495ffdbe5bec0b2741ca6c70 (patch) | |
tree | 28e77f5d7c7e1686256335d0971523360e915887 | |
parent | c48e75ba17a4aeba6338957d2e372c710a9a30c2 (diff) |
[opening_hours] fix
-rw-r--r-- | 3party/opening_hours/rules_evaluation.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/3party/opening_hours/rules_evaluation.cpp b/3party/opening_hours/rules_evaluation.cpp index 7fdac0f3e9..7883471ef5 100644 --- a/3party/opening_hours/rules_evaluation.cpp +++ b/3party/opening_hours/rules_evaluation.cpp @@ -144,12 +144,24 @@ osmoh::TTimespans SplitExtendedHours(osmoh::Timespan span) return result; } +// Spans can be of three different types: +// 1. Normal span - start time is less then end time and end time is less then 24h. Spans of this +// type will be added into |originalNormalizedSpans| as is, |additionalSpan| will be empty. +// 2. Extended span - start time is greater or equal to end time and end time is not equal to +// 00:00 (for ex. 08:00-08:00 or 08:00-03:00), this span will be split into two normal spans +// first will be added into |originalNormalizedSpans| and second will be saved into +// |additionalSpan|. We don't handle more than one occurence of extended span since it is an +// invalid situation. +// 3. Special case - end time is equal to 00:00 (for ex. 08:00-00:00), span of this type will be +// normalized and added into |originalNormalizedSpans|, |additionalSpan| will be empty. +// +// TODO(mgsergio): interpret 00:00 at the end of the span as normal, not extended hours. void SplitExtendedHours(osmoh::TTimespans const & spans, osmoh::TTimespans & originalNormalizedSpans, osmoh::Timespan & additionalSpan) { - // We don't handle more than one occurence of extended span - // since it is an invalid situation. + originalNormalizedSpans.clear(); + additionalSpan = {}; auto it = begin(spans); for (; it != end(spans) && !it->HasExtendedHours(); ++it) @@ -160,7 +172,9 @@ void SplitExtendedHours(osmoh::TTimespans const & spans, auto const splittedSpans = SplitExtendedHours(*it); originalNormalizedSpans.push_back(splittedSpans[0]); - additionalSpan = splittedSpans[1]; + // if a span remains extended after normalization, then it will be split into two different spans. + if (splittedSpans.size() > 1) + additionalSpan = splittedSpans[1]; ++it; std::copy(it, end(spans), back_inserter(originalNormalizedSpans)); |