Commit af1ea6ed authored by Volker Krause's avatar Volker Krause

Fill in missing timezones from the airport database

This allows us to correctly add flights to the calendar, also when
travelling across timezones and/or DST changes.
parent 1097d5cd
......@@ -22,6 +22,9 @@
#include "jsonlddocument.h"
#include "airportdb/airportdb.h"
#include <QDebug>
#include <QTimeZone>
void ExtractorPostprocessor::process(const QVector<QVariant> &data)
{
m_data.reserve(data.size());
......@@ -57,7 +60,8 @@ QVariant ExtractorPostprocessor::processFlight(QVariant flight) const
flight = processProperty(flight, "departureAirport", &ExtractorPostprocessor::processAirport);
flight = processProperty(flight, "arrivalAirport", &ExtractorPostprocessor::processAirport);
// TODO fix timezones
processFlightTime(flight, "departureTime", "departureAirport");
processFlightTime(flight, "arrivalTime", "arrivalAirport");
return flight;
}
......@@ -87,3 +91,25 @@ QVariant ExtractorPostprocessor::processAirport(QVariant airport) const
return airport;
}
void ExtractorPostprocessor::processFlightTime(QVariant &flight, const char *timePropName, const char *airportPropName) const
{
const auto airport = JsonLdDocument::readProperty(flight, airportPropName);
const auto iataCode = JsonLdDocument::readProperty(airport, "iataCode").toString();
if (iataCode.isEmpty()) {
return;
}
auto dt = JsonLdDocument::readProperty(flight, timePropName).toDateTime();
if (!dt.isValid() || dt.timeSpec() != Qt::LocalTime) {
return;
}
const auto tz = AirportDb::timezoneForAirport(AirportDb::IataCode{iataCode});
if (!tz.isValid()) {
return;
}
dt.setTimeZone(tz);
JsonLdDocument::writeProperty(flight, timePropName, dt);
}
......@@ -36,6 +36,7 @@ private:
QVariant processFlightReservation(QVariant res) const;
QVariant processFlight(QVariant flight) const;
QVariant processAirport(QVariant airport) const;
void processFlightTime(QVariant &flight, const char *timePropName, const char *airportPropName) const;
QVector<QVariant> m_data;
};
......
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