File indexing completed on 2024-12-29 04:51:02
0001 /* 0002 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function main(text) { 0008 var reservations = new Array(); 0009 var bookingRef = text.match(/BOOKING REF: ([A-Z0-9]{6})/); 0010 0011 var pos = 0; 0012 while (true) { 0013 var flightHeader = text.substr(pos).match(/FLIGHT *([A-Z0-9]{2}) ([0-9]{3,4}) - ([A-Za-z0-9 ]*?) .*([0-9]{4})\n/); 0014 if (!flightHeader) 0015 break; 0016 var idx = flightHeader.index + flightHeader[0].length; 0017 0018 var res = JsonLd.newFlightReservation(); 0019 res.reservationNumber = bookingRef[1]; 0020 res.reservationFor.airline.iataCode = flightHeader[1]; 0021 res.reservationFor.airline.name = flightHeader[3]; 0022 res.reservationFor.flightNumber = flightHeader[2]; 0023 0024 // TODO support line continuation for DEPARTURE/ARRIVAL 0025 var depLine = text.substr(pos + idx).match(/DEPARTURE: +(.*?) [ -] *([0-9]{2} [A-Z]{3}) ([0-9]{2}:[0-9]{2})/); 0026 if (!depLine) 0027 break; 0028 idx = depLine.index + depLine[0].length; 0029 res.reservationFor.departureAirport.name = depLine[1]; 0030 res.reservationFor.departureTime = JsonLd.toDateTime(depLine[2] + ' ' + flightHeader[4] + ' ' + depLine[3], "dd MMM yyyy hh:mm", "en"); 0031 0032 var arrLine = text.substr(pos + idx).match(/ARRIVAL: +(.*?) [ -] *([0-9]{2} [A-Z]{3}) ([0-9]{2}:[0-9]{2})/); 0033 if (!arrLine) 0034 break; 0035 idx = arrLine.index + arrLine[0].length; 0036 res.reservationFor.arrivalAirport.name = arrLine[1]; 0037 res.reservationFor.arrivalTime = JsonLd.toDateTime(arrLine[2] + ' ' + flightHeader[4] + ' ' + arrLine[3], "dd MMM yyyy hh:mm", "en"); 0038 0039 reservations.push(res); 0040 if (idx == 0) 0041 break; 0042 pos += idx; 0043 } 0044 0045 return reservations; 0046 } 0047 0048 function parseEvent(event) 0049 { 0050 var res = JsonLd.newFlightReservation(); 0051 0052 // force UTC, otherwise we lose the timezone due to JS converting to the local TZ 0053 res.reservationFor.departureTime = event.dtStart.toJSON(); 0054 res.reservationFor.arrivalTime = event.dtEnd.toJSON(); 0055 res.reservationNumber = event.uid.substr(0, 6); 0056 0057 var flight = event.description.match(/Flight: ?(.*) - (\S{2}) (\S{1,4})\n/); 0058 res.reservationFor.airline.name = flight[1]; 0059 res.reservationFor.airline.iataCode = flight[2]; 0060 res.reservationFor.flightNumber = flight[3]; 0061 0062 var from = event.description.match(/From: ?(.*)\n/); 0063 res.reservationFor.departureAirport.name = from[1]; 0064 0065 var to = event.description.match(/To: ?(.*)\n/); 0066 res.reservationFor.arrivalAirport.name = to[1]; 0067 0068 return res; 0069 }