Commit 102d8aff authored by Volker Krause's avatar Volker Krause
Browse files

Apply the same departure day handling we have for flights also for trains

This makes post-processing handle the case that the departure time only
contains a time by using the departure day value to fill the gap.

This avoids extractor scripts having to do error prone date/time
computations in JS, in particular if both values are extracted from
different document nodes (e.g. a barcode and a PDF body).
parent 0a61bfb8
......@@ -42,10 +42,14 @@ KITINERARY_MAKE_OPERATOR(TrainTrip)
QDate TrainTrip::departureDay() const
{
if (d->departureTime.isValid()) {
if (d->departureDay.isValid()) {
return d->departureDay;
}
// pre-1970 dates are used as transient state when we only know the time
if (d->departureTime.isValid() && d->departureTime.date().year() > 1970) {
return d->departureTime.date();
}
return d->departureDay;
return {};
}
void TrainTrip::setDepartureDay(const QDate &value)
......
......@@ -195,8 +195,8 @@ TrainTrip ExtractorPostprocessorPrivate::processTrainTrip(TrainTrip trip) const
trip.setDeparturePlatform(trip.departurePlatform().trimmed());
trip.setDepartureStation(processTrainStation(trip.departureStation()));
trip.setArrivalStation(processTrainStation(trip.arrivalStation()));
trip.setDepartureTime(processTrainTripTime(trip.departureTime(), trip.departureStation()));
trip.setArrivalTime(processTrainTripTime(trip.arrivalTime(), trip.arrivalStation()));
trip.setDepartureTime(processTrainTripTime(trip.departureTime(), trip.departureDay(), trip.departureStation()));
trip.setArrivalTime(processTrainTripTime(trip.arrivalTime(), trip.departureDay(), trip.arrivalStation()));
trip.setTrainNumber(trip.trainNumber().simplified());
trip.setTrainName(trip.trainName().simplified());
return trip;
......@@ -260,12 +260,16 @@ TrainStation ExtractorPostprocessorPrivate::processTrainStation(TrainStation sta
return processPlace(station);
}
QDateTime ExtractorPostprocessorPrivate::processTrainTripTime(QDateTime dt, const TrainStation& station) const
QDateTime ExtractorPostprocessorPrivate::processTrainTripTime(QDateTime dt, QDate departureDay, const TrainStation& station) const
{
if (!dt.isValid()) {
return dt;
}
if (dt.date().year() <= 1970 && departureDay.isValid()) { // we just have the time, but not the day
dt.setDate(departureDay);
}
if (dt.timeSpec() == Qt::TimeZone) {
return dt;
}
......
......@@ -44,7 +44,7 @@ public:
TrainReservation processTrainReservation(TrainReservation res) const;
TrainTrip processTrainTrip(TrainTrip trip) const;
TrainStation processTrainStation(TrainStation station) const;
QDateTime processTrainTripTime(QDateTime dt, const TrainStation &station) const;
QDateTime processTrainTripTime(QDateTime dt, QDate departureDay, const TrainStation &station) const;
BusReservation processBusReservation(BusReservation res) const;
BusTrip processBusTrip(BusTrip trip) const;
......
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