File indexing completed on 2024-12-15 04:21:13

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function parseDateTime(s) {
0007    const r = s.match(/(\d+ [A-Z][a-z]+ \d+) (\d+):(\d\d) (AM|PM)/);
0008     let dt = new Date(Date.parse(r[1] + ' ' + (r[2].length == 1 ? '0' : '') + r[2] + ':' + r[3]));
0009     if (r[4] == 'PM') {
0010         dt.setHours(dt.getHours() + 12);
0011     }
0012     return dt.toJSON().substr(0, 19);
0013 }
0014 
0015 function parseJourney(response)
0016 {
0017     const section = {
0018         mode = 'PublicTransport',
0019         route = {
0020             line = {
0021                 mode = 'Air',
0022                 name = response.flifo.flightNumber
0023             }
0024         },
0025         from = {
0026             identifier = { iata = response.flifo.originAirportCode },
0027             name = response.flifo.originCity
0028         },
0029         to = {
0030             identifier = { iata = response.flifo.destinationAirportCode },
0031             name = response.flifo.destinationCity
0032         },
0033         scheduledArrivalTime: parseDateTime(response.flifo.scheduledArrivalTimeLocal),
0034         expectedArrivalTime: parseDateTime(response.flifo.estimatedArrivalTimeLocal), // also: actualArrivalTime
0035         scheduledDepartureTime: parseDateTime(response.flifo.scheduledDepartureTimeLocal),
0036         expectedDepartureTime: parseDateTime(response.flifo.actualDepartureTimeLocal), // also: estimatedDepartureTime
0037         schedluedDeparturePlatform: response.flifo.departureGate,
0038         scheduledArrivalPlatform: response.flifo.arrivalGate
0039     };
0040     return { sections = [section] };
0041 }