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

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function parseBarcode(barcode) {
0008     // barcode content
0009     // 13x FTR number
0010     // 29x traveler family name
0011     // 2x coach number
0012     // 6x seat number
0013     // 4x departure station identifier
0014     // 4x arrival station identifier
0015     // 3x carrier identifier
0016     // 4x train number
0017     // 8x departure date yyyyMMdd
0018     // 4x departure time hhmm
0019     // 20x given name
0020     // 2x stuff, often empty
0021     // 5x stuff, possibly containing Adult/Child/etc info
0022     // 6x confirmation number
0023     // 12x purchase date/time as yyyyMMddhhmm
0024     // 6x stuff, presumably class being part of this
0025 
0026     var res = JsonLd.newTrainReservation();
0027     res.reservationFor.provider = barcode.substr(58, 3);
0028     res.reservationFor.trainNumber = barcode.substr(61, 4).trim();
0029     res.reservationFor.departureTime = JsonLd.toDateTime(barcode.substr(65, 12), "yyyyMMddhhmm", "en");
0030     res.reservationFor.departureStation.identifier = 'via:' + barcode.substr(50, 4);
0031     res.reservationFor.departureStation.name = barcode.substr(50, 4);
0032     res.reservationFor.arrivalStation.identifier = 'via:' + barcode.substr(54, 4);
0033     res.reservationFor.arrivalStation.name = barcode.substr(54, 4);
0034     res.reservedTicket.ticketedSeat.seatSection = barcode.substr(42, 2).trim();
0035     res.reservedTicket.ticketedSeat.seatNumber = barcode.substr(44, 6).trim();
0036     res.reservedTicket.ticketToken = "azteccode:" + barcode;
0037     res.underName.familyName = barcode.substr(13, 29).trim();
0038     res.underName.givenName = barcode.substr(77, 20).trim();
0039     res.reservationNumber = barcode.substr(104, 6);
0040     return res;
0041 }
0042 
0043 function parseBoardingPass(pdf, node, triggerNode) {
0044     var res = node.result[0];
0045     const text = pdf.pages[triggerNode.location].text;
0046     const stationNames = text.match(/FTR\s*:\s*\d+\n(.*)   +(.*)\n/);
0047     res.reservationFor.departureStation.name = stationNames[1];
0048     res.reservationFor.arrivalStation.name = stationNames[2];
0049     const arrivalDate = text.match(/Date\s*:.*Date\s*:\s*\w+\.\s*(.*)\n/);
0050     const arrivalTime = text.match(/Arrival\s*:\s*(.*)\n/);
0051     console.log(arrivalDate[1] + ' ' + arrivalTime[1]);
0052     res.reservationFor.arrivalTime = JsonLd.toDateTime(arrivalDate[1] + ' ' + arrivalTime[1], 'MMM d, yyyy HH:mm AP', 'en');
0053     return res;
0054 }