Commit 957b3fa1 authored by Volker Krause's avatar Volker Krause
Browse files

Consider non-location change elements when determining location as well

When all we have at a given time is e.g. a hotel or event with a defined
location, assume that's where we are.

BUG: 455083
parent 7fd6b845
Pipeline #192468 passed with stage
in 4 minutes and 37 seconds
[
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationNumber": "XXX007",
"reservationStatus": "http://schema.org/Confirmed",
"reservationFor": {
"@type": "Flight",
"flightNumber": "1234",
"departureAirport": {
"@type": "Airport",
"iataCode": "STR"
},
"departureTime": "2017-03-04T11:00:00-05:00",
"arrivalAirport": {
"@type": "Airport",
"iataCode": "MUC"
},
"arrivalTime": "2017-03-05T13:25:00-06:00"
}
},
{
"@context": "http://schema.org",
"@type": "LodgingReservation",
"checkinDate": "2022-06-13T15:00:00+02:00",
"checkoutDate": "2022-06-17T10:00:00+02:00",
"reservationFor": {
"@type": "LodgingBusiness",
"address": {
"@type": "PostalAddress",
"addressCountry": "DE",
"addressLocality": "Berlin",
"addressRegion": "BE",
"postalCode": "10553"
},
"name": "Some Hotel"
}
}
]
......@@ -16,6 +16,7 @@
#include <QtTest/qtest.h>
#include <QSignalSpy>
#include <QStandardPaths>
#include <QTimeZone>
using namespace KItinerary;
......@@ -85,6 +86,27 @@ private Q_SLOTS:
QCOMPARE(controller.subTitle(), QLatin1String("Neujahr"));
QCOMPARE(controller.isHoliday(), true);
}
void testBug455083()
{
ReservationManager mgr;
Test::clearAll(&mgr);
ApplicationController ctrl;
ctrl.setReservationManager(&mgr);
// test data puts our known location to DE-BY and then adds a hotel in DE-BE for the BY-only public holiday on 2022-06-16
ctrl.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/bug455083.json")));
TimelineModel model;
model.setCurrentDateTime(QDateTime({2022, 6, 14}, {8, 0}));
model.setReservationManager(&mgr);
QCOMPARE(LocationHelper::regionCode(model.locationAtTime(QDateTime({2022, 6, 12}, {0, 0}, QTimeZone("Europe/Berlin")))), QLatin1String("DE-BY"));
QCOMPARE(LocationHelper::regionCode(model.locationAtTime(QDateTime({2022, 6, 13}, {0, 0}, QTimeZone("Europe/Berlin")))), QLatin1String("DE-BY"));
QCOMPARE(LocationHelper::regionCode(model.locationAtTime(QDateTime({2022, 6, 14}, {0, 0}, QTimeZone("Europe/Berlin")))), QLatin1String("DE-BE"));
QCOMPARE(LocationHelper::regionCode(model.locationAtTime(QDateTime({2022, 6, 16}, {0, 0}, QTimeZone("Europe/Berlin")))), QLatin1String("DE-BE"));
QCOMPARE(LocationHelper::regionCode(model.locationAtTime(QDateTime({2022, 6, 17}, {0, 0}, QTimeZone("Europe/Berlin")))), QLatin1String("DE-BY"));
QCOMPARE(LocationHelper::regionCode(model.locationAtTime(QDateTime({2022, 6, 18}, {0, 0}, QTimeZone("Europe/Berlin")))), QLatin1String("DE-BY"));
}
};
QTEST_GUILESS_MAIN(TimelineSectionDelegateControllerTest)
......
......@@ -883,13 +883,28 @@ QVariant TimelineModel::locationAtTime(const QDateTime& dt) const
return {};
}
for (--it; it != m_elements.begin(); --it) {
if (!(*it).isReservation() || !(*it).isLocationChange()) {
continue;
for (--it ;; --it) {
// this is a still ongoing non-location change
if (it != m_elements.end() && !(*it).isLocationChange() && (*it).endDateTime().isValid() && (*it).endDateTime() > dt) {
if ((*it).isReservation()) {
auto loc = LocationUtil::location(m_resMgr->reservation((*it).batchId()));
if (LocationUtil::geo(loc).isValid() || !LocationUtil::address(loc).addressCountry().isEmpty()) {
return loc;
}
}
}
if ((*it).isReservation() && (*it).isLocationChange()) {
// TODO make this work for transfers too
const auto res = m_resMgr->reservation((*it).batchId());
return LocationUtil::arrivalLocation(res);
}
if (it == m_elements.begin()) {
break;
}
const auto res = m_resMgr->reservation((*it).batchId());
return LocationUtil::arrivalLocation(res);
}
return {};
}
......
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