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

0001 /*
0002    SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function parseEvent(event) {
0007     let reservations = [];
0008     let idx = 0;
0009     while (true) {
0010         const trip = event.description.substr(idx).match(/Journey Details: (.*) \(([A-Z]{3})\) to (.*) \(([A-Z]{3})\), *dep *(\d\d):(\d\d), *arr *(\d\d):(\d\d)/);
0011         if (!trip) {
0012             break;
0013         }
0014         idx += trip.index + trip[0].length;
0015 
0016         let res = JsonLd.newTrainReservation();
0017         let depDt = new Date(event.dtStart);
0018         depDt.setHours(trip[5]);
0019         depDt.setMinutes(trip[6]);
0020         res.reservationFor.departureTime = depDt;
0021         let arrDt = new Date(event.dtStart);
0022         arrDt.setHours(trip[7]);
0023         arrDt.setMinutes(trip[8]);
0024         res.reservationFor.arrivalTime = arrDt;
0025         res.reservationFor.departureStation.name = trip[1];
0026         res.reservationFor.departureStation.identifier = 'uk:' + trip[2];
0027         res.reservationFor.arrivalStation.name = trip[3];
0028         res.reservationFor.arrivalStation.identifier = 'uk:' + trip[4];
0029         reservations.push(res);
0030     }
0031 
0032     reservations[0].reservationFor.departureTime = JsonLd.readQDateTime(event, 'dtStart');
0033     reservations[reservations.length - 1].reservationFor.arrivalTime = JsonLd.readQDateTime(event, 'dtEnd');
0034     return reservations;
0035 }