Commit 5f58e3b0 authored by Volker Krause's avatar Volker Krause
Browse files

Take modification time into account when merging reservations

That is, a newer one now always takes precedence, even if it comes first
in the input list.
parent e9b875dd
[
{
"@type": "FlightReservation",
"airplaneSeat": "06D",
"modifiedTime": "2019-12-19T00:00:00",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "XX"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "CPH",
"name": "Copenhagen"
},
"arrivalTime": "2020-01-05T12:15:00.000",
"departureAirport": {
"@type": "Airport",
"iataCode": "PRG",
"name": "Prag"
},
"departureTime": "2020-01-05T10:55:00.000",
"flightNumber": "1234"
},
"reservationNumber": "XXX007"
}
]
[{
"@context": "http://schema.org",
"@type": "FlightReservation",
"airplaneSeat": "27E",
"modifiedTime": "2020-01-04T00:00:00",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "DX"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "CPH",
"name": "Copenhagen"
},
"arrivalTime": "2020-01-05T12:15:00",
"departureAirport": {
"@type": "Airport",
"iataCode": "PRG",
"name": "Prag"
},
"departureDay": "2021-01-05",
"departureTime": "2020-01-05T10:55:00",
"flightNumber": "1234"
},
"reservationNumber": "XXX007",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecCode:M1..."
}
}]
[
{
"@context": "http://schema.org",
"@type": "FlightReservation",
"airplaneSeat": "27E",
"modifiedTime": "2020-01-04T00:00:00",
"reservationFor": {
"@type": "Flight",
"airline": {
"@type": "Airline",
"iataCode": "DX"
},
"arrivalAirport": {
"@type": "Airport",
"iataCode": "CPH"
},
"departureAirport": {
"@type": "Airport",
"iataCode": "PRG"
},
"departureDay": "2021-01-05",
"flightNumber": "1234"
},
"reservationNumber": "XXX007",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecCode:M1..."
}
}
]
......@@ -534,6 +534,15 @@ QVariant MergeUtil::merge(const QVariant &lhs, const QVariant &rhs)
return {};
}
// prefer the element with the newer mtime, if we have that information
if (JsonLd::canConvert<Reservation>(lhs) && JsonLd::canConvert<Reservation>(rhs)) {
const auto lhsDt = JsonLd::convert<Reservation>(lhs).modifiedTime();
const auto rhsDt = JsonLd::convert<Reservation>(rhs).modifiedTime();
if (lhsDt.isValid() && rhsDt.isValid() && rhsDt < lhsDt) {
return MergeUtil::merge(rhs, lhs);
}
}
auto res = lhs;
const auto mo = QMetaType(res.userType()).metaObject();
for (int i = 0; i < mo->propertyCount(); ++i) {
......
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