Commit 8eed85bc authored by Volker Krause's avatar Volker Krause
Browse files

Don't add transfers for unbound tickets

The screenshots in issue #29 show this happening, and it's obviously
pointless given unbound tickets have no exact times associated yet.
parent 9dfd0963
......@@ -11,6 +11,8 @@
#include <KItinerary/Reservation>
#include <KItinerary/TrainTrip>
#include <QDateTime>
using namespace KItinerary;
std::pair<QString, QString> ReservationHelper::lineNameAndNumber(const QVariant &res)
......@@ -49,3 +51,31 @@ bool ReservationHelper::equals(const QVariant &lhs, const QVariant &rhs)
return false;
}
QDateTime ReservationHelper::departureTime(const QVariant &res)
{
if (JsonLd::isA<TrainReservation>(res)) {
return res.value<TrainReservation>().reservationFor().value<TrainTrip>().departureTime();
}
if (JsonLd::isA<BusReservation>(res)) {
return res.value<BusReservation>().reservationFor().value<BusTrip>().departureTime();
}
if (JsonLd::isA<FlightReservation>(res)) {
return res.value<FlightReservation>().reservationFor().value<Flight>().departureTime();
}
return {};
}
QDateTime ReservationHelper::arrivalTime(const QVariant &res)
{
if (JsonLd::isA<TrainReservation>(res)) {
return res.value<TrainReservation>().reservationFor().value<TrainTrip>().arrivalTime();
}
if (JsonLd::isA<BusReservation>(res)) {
return res.value<BusReservation>().reservationFor().value<BusTrip>().arrivalTime();
}
if (JsonLd::isA<FlightReservation>(res)) {
return res.value<FlightReservation>().reservationFor().value<Flight>().arrivalTime();
}
return {};
}
......@@ -9,6 +9,7 @@
#include <utility>
class QDateTime;
class QString;
class QVariant;
......@@ -18,6 +19,12 @@ namespace ReservationHelper
std::pair<QString, QString> lineNameAndNumber(const QVariant &res);
bool equals(const QVariant &lhs, const QVariant &rhs);
/** Returns the arrival/departure time if available.
* This returns an invalid time for unbound train tickets or bare flight boarding passes.
*/
QDateTime departureTime(const QVariant &res);
QDateTime arrivalTime(const QVariant &res);
}
#endif // RESERVATIONHELPER_H
......@@ -8,13 +8,13 @@
#include "logging.h"
#include "favoritelocationmodel.h"
#include "publictransport.h"
#include "reservationhelper.h"
#include "reservationmanager.h"
#include "tripgroup.h"
#include "tripgroupmanager.h"
#include <KItinerary/LocationUtil>
#include <KItinerary/Reservation>
#include <KItinerary/SortUtil>
#include <KPublicTransport/Journey>
#include <KPublicTransport/JourneyReply>
......@@ -199,11 +199,11 @@ void TransferManager::checkReservation(const QString &resId)
const auto res = m_resMgr->reservation(resId);
const auto now = currentDateTime();
if (SortUtil::endDateTime(res) < now) {
if (ReservationHelper::arrivalTime(res) < now) {
return;
}
checkReservation(resId, res, Transfer::After);
if (SortUtil::startDateTime(res) < now) {
if (ReservationHelper::departureTime(res) < now) {
return;
}
checkReservation(resId, res, Transfer::Before);
......@@ -236,7 +236,7 @@ void TransferManager::checkReservation(const QString &resId, const QVariant &res
TransferManager::CheckTransferResult TransferManager::checkTransferBefore(const QString &resId, const QVariant &res, Transfer &transfer) const
{
transfer.setAnchorTime(SortUtil::startDateTime(res));
transfer.setAnchorTime(ReservationHelper::departureTime(res));
const auto isLocationChange = LocationUtil::isLocationChange(res);
QVariant toLoc;
if (isLocationChange) {
......@@ -292,7 +292,7 @@ TransferManager::CheckTransferResult TransferManager::checkTransferBefore(const
TransferManager::CheckTransferResult TransferManager::checkTransferAfter(const QString &resId, const QVariant &res, Transfer &transfer) const
{
transfer.setAnchorTime(SortUtil::endDateTime(res));
transfer.setAnchorTime(ReservationHelper::arrivalTime(res));
const auto isLocationChange = LocationUtil::isLocationChange(res);
QVariant fromLoc;
if (isLocationChange) {
......
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