Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0b1b3320 authored by Volker Krause's avatar Volker Krause

Determine the timezone when having multiple non-conflicting candidates

parent e73b3d2b
[
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "CA",
"name": "AIR CHINA"
},
"arrivalAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "JP"
},
"name": "OSAKA JP KANSAI INTERNATIONAL"
},
"arrivalTime": {
"@type": "QDateTime",
"@value": "2010-01-01T20:30:00+09:00",
"timezone": "Asia/Tokyo"
},
"departureAirport": {
"@type": "Airport",
"address": {
"@type": "PostalAddress",
"addressCountry": "CN"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 31.143299102783203,
"longitude": 121.80500030517578
},
"iataCode": "PVG",
"name": "SHANGHAI CN PUDONG INTL"
},
"departureDay": "2010-01-01",
"departureTime": {
"@type": "QDateTime",
"@value": "2018-01-01T17:30:00+08:00",
"timezone": "Asia/Shanghai"
},
"flightNumber": "123"
},
"reservationNumber": "XXX007"
}
]
[
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "CA",
"name": "AIR CHINA"
},
"arrivalAirport": {
"@type": "Airport",
"name": "OSAKA JP KANSAI INTERNATIONAL"
},
"arrivalTime": "2010-01-01T11:30:00Z",
"departureAirport": {
"@type": "Airport",
"iataCode": "PVG",
"name": "SHANGHAI CN PUDONG INTL"
},
"departureDay": "2010-01-01",
"departureTime": "2018-01-01T17:30:00+08:00",
"flightNumber": "123"
},
"reservationNumber": "XXX007"
}
]
......@@ -40,9 +40,9 @@ Flight FlightPostProcessor::processFlight(Flight flight)
flight.setDepartureAirport(processAirport(flight.departureAirport(), m_departureCodes));
flight.setArrivalAirport(processAirport(flight.arrivalAirport(), m_arrivalCodes));
flight.setAirline(processAirline(flight.airline()));
flight.setBoardingTime(processFlightTime(flight.boardingTime(), flight, flight.departureAirport()));
flight.setDepartureTime(processFlightTime(flight.departureTime(), flight, flight.departureAirport()));
flight.setArrivalTime(processFlightTime(flight.arrivalTime(), flight, flight.arrivalAirport()));
flight.setBoardingTime(processFlightTime(flight.boardingTime(), flight, m_departureCodes));
flight.setDepartureTime(processFlightTime(flight.departureTime(), flight, m_departureCodes));
flight.setArrivalTime(processFlightTime(flight.arrivalTime(), flight, m_arrivalCodes));
flight = ExtractorUtil::extractTerminals(flight);
return flight;
}
......@@ -87,7 +87,7 @@ Airline FlightPostProcessor::processAirline(Airline airline) const
return airline;
}
QDateTime FlightPostProcessor::processFlightTime(QDateTime dt, const Flight &flight, const Airport &airport) const
QDateTime FlightPostProcessor::processFlightTime(QDateTime dt, const Flight &flight, const std::vector<KnowledgeDb::IataCode> &codes) const
{
if (!dt.isValid()) {
return dt;
......@@ -97,12 +97,12 @@ QDateTime FlightPostProcessor::processFlightTime(QDateTime dt, const Flight &fli
dt.setDate(flight.departureDay());
}
if (dt.timeSpec() == Qt::TimeZone || airport.iataCode().isEmpty()) {
if (dt.timeSpec() == Qt::TimeZone || codes.empty()) {
return dt;
}
const auto tz = KnowledgeDb::timezoneForAirport(KnowledgeDb::IataCode{airport.iataCode()});
if (!tz.isValid()) {
const auto tz = KnowledgeDb::timezoneForAirport(KnowledgeDb::IataCode{codes[0]});
if (!tz.isValid() || !std::all_of(codes.begin(), codes.end(), [tz](const auto &iataCode) { return KnowledgeDb::timezoneForAirport(iataCode) == tz; })) {
return dt;
}
......
......@@ -41,7 +41,7 @@ public:
private:
Airport processAirport(Airport airport, const std::vector<KnowledgeDb::IataCode> &codes) const;
Airline processAirline(Airline airline) const;
QDateTime processFlightTime(QDateTime dt, const Flight &flight, const Airport &airport) const;
QDateTime processFlightTime(QDateTime dt, const Flight &flight, const std::vector<KnowledgeDb::IataCode> &codes) const;
void lookupAirportCodes(const Airport &airport, std::vector<KnowledgeDb::IataCode> &codes) 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