Commit 405c78dd authored by David Faure's avatar David Faure
Browse files

Simplify "Feb 1-29" to "Feb"

BUG: 446252
parent 9bb6be75
Pipeline #105632 passed with stage
in 40 seconds
......@@ -366,6 +366,9 @@ private Q_SLOTS:
T3("Sa-Mo 10:00-23:00, Th 10:00-23:00", "Sa-Mo 10:00-23:00, Th 10:00-23:00", "Sa-Mo,Th 10:00-23:00"); // beginDay > endDay
T3("Sa-Mo 10:00-23:00, Fr 10:00-23:00", "Sa-Mo 10:00-23:00, Fr 10:00-23:00", "Fr-Mo 10:00-23:00"); // beginDay > endDay
T3("Su-Th 10:00-23:00, Fr-Sa 10:00-23:00", "Su-Th 10:00-23:00, Fr-Sa 10:00-23:00", "Mo-Su 10:00-23:00"); // beginDay > endDay
T3("Feb 1-Feb 29 Mo-Su 10:30-20:30; Aug 1-Aug 31 Mo-Fr 10:30-12:00; PH closed",
"Feb 01-29 Mo-Su 10:30-20:30; Aug 01-31 Mo-Fr 10:30-12:00; PH closed",
"Feb Mo-Su 10:30-20:30; Aug Mo-Fr 10:30-12:00; PH closed");
// complex or creative 24/7 use
T("06:00-01:00 open \"Dining in\" || 24/7 \"Drive-through\"");
......
......@@ -194,6 +194,9 @@ void OpeningHoursPrivate::simplify()
if (rule->m_weekdaySelector) {
rule->m_weekdaySelector->simplify();
}
if (rule->m_monthdaySelector) {
rule->m_monthdaySelector->simplify();
}
}
}
......
......@@ -454,6 +454,24 @@ QByteArray MonthdayRange::toExpression(const MonthdayRange &prev) const
return expr;
}
void MonthdayRange::simplify()
{
// "Feb 1-29" => "Feb" (#446252)
if (begin.variableDate == Date::FixedDate &&
end.variableDate == Date::FixedDate &&
begin.year == end.year &&
begin.month && end.month &&
begin.month == end.month &&
begin.day && end.day) {
// The year doesn't matter, but take one with a leap day, for Feb 1-29
const int lastDay = QDate{2004, end.month, end.day}.daysInMonth();
if (begin.day == 1 && end.day == lastDay) {
begin.day = 0;
end.day = 0;
}
}
}
int YearRange::requiredCapabilities() const
{
return Capability::None;
......
......@@ -215,6 +215,7 @@ public:
int requiredCapabilities() const;
SelectorResult nextInterval(const Interval &interval, const QDateTime &dt, OpeningHoursPrivate *context) const;
QByteArray toExpression(const MonthdayRange &prev) const;
void simplify();
Date begin = { 0, 0, 0, Date::FixedDate, { 0, 0, 0 } };
Date end = { 0, 0, 0, Date::FixedDate, { 0, 0, 0 } };
......
Supports Markdown
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