Commit 9909dafe authored by Volker Krause's avatar Volker Krause
Browse files

Provide valid closed intervals for always closed expressions

In that case the first half of this method will not find a single valid
non-closed interval, and so i.begin() is invalid here.
parent 7e0faf67
Pipeline #282661 skipped
......@@ -93,6 +93,26 @@ private Q_SLOTS:
QCOMPARE(intervals[1].state(), Interval::Closed);
QCOMPARE(intervals[2].state(), Interval::Open);
}
void testPermanentlyClosed()
{
IntervalModel model;
QAbstractItemModelTester modelTest(&model);
OpeningHours oh("Mo-Su off");
QCOMPARE(oh.error(), OpeningHours::NoError);
model.setOpeningHours(oh);
model.setBeginDate({2022, 12, 1});
model.setEndDate({2022, 12, 2});
QCOMPARE(model.rowCount(), 1);
const auto intervals = model.index(0, 0).data(IntervalModel::IntervalsRole).value<std::vector<Interval>>();
QCOMPARE(intervals.size(), 1);
QCOMPARE(intervals[0].begin(), QDateTime({ 2022, 12, 1 }, {0, 0}));
QCOMPARE(intervals[0].end(), QDateTime({ 2022, 12, 2 }, {0, 0}));
QCOMPARE(intervals[0].state(), Interval::Closed);
}
};
QTEST_GUILESS_MAIN(IntervalModelTest)
......
......@@ -558,7 +558,7 @@ Interval OpeningHours::interval(const QDateTime &dt) const
if (rule->state() != Interval::Closed) {
continue;
}
const auto j = rule->nextInterval(i.begin(), d.data()).interval;
const auto j = rule->nextInterval(i.begin().isValid() ? i.begin() : alignedTime, d.data()).interval;
if (!j.isValid() || !i.intersects(j)) {
continue;
}
......
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