File indexing completed on 2024-12-29 04:51:06
0001 /* 0002 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function parseConfirmation(content) { 0007 var reservations = []; 0008 const text = content.pages[0].text; 0009 const ref = text.match(/Reference.\s*([A-Z0-9]{6})/)[1]; 0010 var idx = 0; 0011 while (true) { 0012 const leg = text.substr(idx).match(/Flight Time\n\s*(\d\d:\d\d)\s*(\d\d:\d\d)\n\s*(\d\d\d\d\/\d\d\/\d\d)\s*\(.*\)\s+([A-Z0-9]{2}\d{1,4}).*\n\s*(.*?)\s\s+(.*)/); 0013 if (!leg) { 0014 break; 0015 } 0016 idx += leg.index + leg[0].length; 0017 0018 var flight = JsonLd.newFlightReservation(); 0019 flight.reservationNumber = ref; 0020 flight.reservationFor.departureAirport.name = leg[5]; 0021 flight.reservationFor.departureTime = JsonLd.toDateTime(leg[3] + leg[1], "yyyy/MM/ddhh:mm", "jp"); 0022 flight.reservationFor.arrivalAirport.name = leg[6]; 0023 flight.reservationFor.arrivalTime = JsonLd.toDateTime(leg[3] + leg[2], "yyyy/MM/ddhh:mm", "jp"); 0024 flight.reservationFor.flightNumber = leg[4]; 0025 0026 // TODO handle multiple passengers, once we have a sample for that 0027 const pas = text.substr(idx).match(/\s*(.*)\/(.*?) +.* (\d{1,2}[A-K]).*\n/); 0028 idx += pas.index + pas[0].length; 0029 0030 flight.underName.familyName = pas[1]; 0031 flight.underName.givenName = pas[2]; 0032 flight.airplaneSeat = pas[3]; 0033 0034 reservations.push(flight); 0035 } 0036 return reservations; 0037 }