Commit cf53d9f8 authored by David Faure's avatar David Faure
Browse files

The recent commit "generalize to comma" was about a simplification.

=> move that feature to simplifiedExpression. No reason to generate
errors due to "Mo 12:00-15:00, Mo 18:00-24:00".
But we can simplify this when we get a chance to modify it.
parent 16292639
Pipeline #54918 passed with stage
in 20 seconds
......@@ -317,8 +317,6 @@ private Q_SLOTS:
T2("Mo-Sa 12:00-15:00; 18:00-24:00", "Mo-Sa 12:00-15:00,18:00-24:00");
T2("Mo-Sa 12:00-15:00; Mo-Sa 18:00-24:00", "Mo-Sa 12:00-15:00,18:00-24:00");
T2("Mo 12:00-15:00; Mo 18:00-24:00", "Mo 12:00-15:00,18:00-24:00");
T2("Mo-Sa 12:00-15:00, Mo-Sa 18:00-24:00", "Mo-Sa 12:00-15:00,18:00-24:00");
T2("Mo 12:00-15:00, Mo 18:00-24:00", "Mo 12:00-15:00,18:00-24:00");
// recovery from wrong time selector separators
T3("Dimanche Fermé Lundi 08:00 – 12:30 14:00 – 19:00 Mardi 08:00 – 12:30 14:00 – 19:00 Mercredi 08:00 – 12:30 14:00 – 19:00 Jeudi 08:00 – 12:30 14:00 – 19:00 Vendredi 08:00 – 12:30 14:00 – 19:00 Samedi 08:00 – 12:30 14:30 – 18:00",
......@@ -332,8 +330,10 @@ private Q_SLOTS:
// Simplification of the output
T3("Mo 08:00-13:00; Tu 08:00-13:00", "Mo 08:00-13:00; Tu 08:00-13:00", "Mo,Tu 08:00-13:00");
T3("Mo-Th 08:00-13:00; Sa[1],Su[2] 08:00-13:00", "Mo-Th 08:00-13:00; Sa[1],Su[-1] 08:00-13:00", "Mo-Th,Sa[1],Su[-1] 08:00-13:00");
T3("Mo-Th 08:00-13:00; Sa[1],Su[-1] 08:00-13:00", "Mo-Th 08:00-13:00; Sa[1],Su[-1] 08:00-13:00", "Mo-Th,Sa[1],Su[-1] 08:00-13:00");
T("easter +1 day 08:00-13:00; Tu,Sa-Su 08:00-13:00"); // does not simplify
T3("Mo-Sa 12:00-15:00, Mo-Sa 18:00-24:00", "Mo-Sa 12:00-15:00, Mo-Sa 18:00-24:00", "Mo-Sa 12:00-15:00,18:00-24:00");
T3("Mo 12:00-15:00, Mo 18:00-24:00", "Mo 12:00-15:00, Mo 18:00-24:00", "Mo 12:00-15:00,18:00-24:00");
#undef T
#undef T2
#undef T3
......
......@@ -101,14 +101,14 @@ void OpeningHoursPrivate::autocorrect()
appendSelector(prevRule->m_timeSelector.get(), std::move(rule->m_timeSelector));
it = std::prev(m_rules.erase(it));
}
}
if (rule->m_ruleType == Rule::AdditionalRule || rule->m_ruleType == Rule::NormalRule) {
// Both rules have exactly the same selector apart from time
// Ex: "Mo-Sa 12:00-15:00; Mo-Sa 18:00-24:00" => "Mo-Sa 12:00-15:00,18:00-24:00"
// Obviously a bug, it was overwriting the 12:00-15:00 range.
// For now this only supports weekday selectors, could be extended
if (rule->selectorCount() == prevRule->selectorCount()
&& rule->m_timeSelector
&& prevRule->m_timeSelector
else if (rule->selectorCount() == prevRule->selectorCount()
&& rule->m_timeSelector && prevRule->m_timeSelector
&& !rule->hasComment() && !prevRule->hasComment()
&& rule->selectorCount() == 2 && rule->m_weekdaySelector && prevRule->m_weekdaySelector
// slower than writing an operator==, but so much easier to write :)
&& rule->m_weekdaySelector->toExpression() == prevRule->m_weekdaySelector->toExpression()
......@@ -136,7 +136,6 @@ void OpeningHoursPrivate::simplify()
return selector->holiday == WeekdayRange::NoHoliday
&& !selector->lhsAndSelector;
};
// Both rules have the same time and a different weekday selector
// Mo 08:00-13:00; Tu 08:00-13:00 => Mo,Tu 08:00-13:00
if (rule->selectorCount() == prevRule->selectorCount()
......@@ -149,6 +148,23 @@ void OpeningHoursPrivate::simplify()
// We could of course also turn Mo,Tu,We,Th into Mo-Th...
appendSelector(prevRule->m_weekdaySelector.get(), std::move(rule->m_weekdaySelector));
it = std::prev(m_rules.erase(it));
continue;
}
}
if (rule->m_ruleType == Rule::AdditionalRule) {
// Both rules have exactly the same selector apart from time
// Ex: "Mo 12:00-15:00, Mo 18:00-24:00" => "Mo 12:00-15:00,18:00-24:00"
// For now this only supports weekday selectors, could be extended
if (rule->selectorCount() == prevRule->selectorCount()
&& rule->m_timeSelector && prevRule->m_timeSelector
&& !rule->hasComment() && !prevRule->hasComment()
&& rule->selectorCount() == 2 && rule->m_weekdaySelector && prevRule->m_weekdaySelector
// slower than writing an operator==, but so much easier to write :)
&& rule->m_weekdaySelector->toExpression() == prevRule->m_weekdaySelector->toExpression()
) {
appendSelector(prevRule->m_timeSelector.get(), std::move(rule->m_timeSelector));
it = std::prev(m_rules.erase(it));
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment