File indexing completed on 2024-12-29 04:51:04

0001 /*
0002    SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function extractEvent(ev) {
0007     let res = JsonLd.newFlightReservation();
0008 
0009     // force UTC, otherwise we lose the timezone due to JS converting to the local TZ
0010     res.reservationFor.departureTime = ev.dtStart.toJSON();
0011     res.reservationFor.arrivalTime = ev.dtEnd.toJSON();
0012 
0013     const flight = ev.description.match(/Flight no: (\S{2}) (\d+)/);
0014     res.reservationFor.airline.iataCode = flight[1];
0015     res.reservationFor.flightNumber = flight[2];
0016     res.reservationFor.airline.name = ev.description.match(/operated by: (.*)/)[1];
0017 
0018     const dep = ev.location.match(/from (.*\(([A-Z]{3})\).*)/);
0019     res.reservationFor.departureAirport.name = dep[1];
0020     res.reservationFor.departureAirport.iataCode = dep[2];
0021 
0022     const arr = ev.summary.match(/to (.*\(([A-Z]{3})\).*)/);
0023     res.reservationFor.arrivalAirport.name = arr[1];
0024     res.reservationFor.arrivalAirport.iataCode = arr[2];
0025 
0026     res.reservationNumber = ev.description.match(/Reservation code: (.*)/)[1];
0027     return res;
0028 }
0029 
0030 function extractBoardingPass(iata, node, pdfNode) {
0031     let res = node.result[0];
0032     const text = pdfNode.content.pages[node.location].text;
0033     let boarding = text.match(/(\d\d:\d\d) (?:GROUP (\S+))?  +\d+[A-Z]/);
0034     if (!boarding)
0035         boarding = text.match(/(\d\d:\d\d) +\d\d:\d\d/);
0036     res.reservationFor.boardingTime = JsonLd.toDateTime(boarding[1], 'hh:mm', 'en');
0037     res.boardingGroup = boarding[2];
0038     return res;
0039 }