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

0001 /*
0002    SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function parseEvent(event)
0008 {
0009     var res;
0010     if (event.summary.match(/(?:Flight|Flug)/i)) {
0011         res = JsonLd.newFlightReservation();
0012 
0013         // force UTC, otherwise we lose the timezone due to JS converting to the local TZ
0014         res.reservationFor.departureTime = event.dtStart.toJSON();
0015         res.reservationFor.arrivalTime = event.dtEnd.toJSON();
0016 
0017         var flight = event.description.match(/(?:Flight no|Flugnr.):\s*(\w{2}) (\d{1,4})\n?.*(?:by|von): (.+)\n/);
0018         res.reservationFor.airline.name = flight[3];
0019         res.reservationFor.airline.iataCode = flight[1];
0020         res.reservationFor.flightNumber = flight[2];
0021 
0022         var from = event.description.match(/(?:From|Von):\s+(.*)\n/);
0023         res.reservationFor.departureAirport.name = from[1];
0024 
0025         var to = event.description.match(/(?:To|Nach):\s+(.*)\n/);
0026         res.reservationFor.arrivalAirport.name = to[1];
0027 
0028     } else if (event.summary.startsWith("Mietwagen")) {
0029         res = JsonLd.newRentalCarReservation();
0030 
0031         var pickup = event.description.match(/Abgabeort:\s*(.*)\n/);
0032         res.pickupLocation.name = pickup[1]; // TODO split address
0033 
0034         var dropoff = event.description.match(/Annahmeort:\s*(.*)\n/);
0035         res.dropoffLocation.name = dropoff[1]; // TODO dito
0036 
0037         // force UTC, otherwise we lose the timezone due to JS converting to the local TZ
0038         res.pickupTime = event.dtStart.toJSON();
0039         res.dropoffTime = event.dtEnd.toJSON();
0040 
0041         var provider = event.description.match(/Mietwagenfirma:\s*(.*)\n/);
0042         res.reservationFor.rentalCompany.name = provider[1];
0043         var model = event.description.match(/Wagenkl.\/Typ:\s*(.*)\n/);
0044         res.reservationFor.name = model[1];
0045     } else {
0046         return null;
0047     }
0048 
0049     var refNum = event.description.match(/(?:Reservation code|Buchungsnummer|Buchungscode):\s(.+)\n/);
0050     res.reservationNumber = refNum[1];
0051 
0052     return res;
0053 }