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

0001 /*
0002     SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function main(content) {
0008     var res = JsonLd.newEventReservation();
0009 
0010     var name = content.match(/Name: (.*)/)[1]
0011     var theDate = content.match(/Termin Datum: (.*)/)[1]
0012     var theTime = content.match(/Termin Uhrzeit: (.*) Uhr/)[1]
0013     var addr = content.match(/Adresse der Teststation: (.*), (.*), ([0-9]*) (.*)/)
0014 
0015     var cancelUrlMatch = content.match(/FΓΌr Absagen verwenden Sie bitte folgenden Link: (.*)/)
0016 
0017     const address = JsonLd.newObject("PostalAddress")
0018     address.addressCountry = "DE"
0019     address.addressLocality = addr[4]
0020     address.postalCode = addr[3]
0021     address.streetAddress = addr[2]
0022 
0023     res.reservationFor.name = name
0024 
0025     // FIXME some cancel urls are not matched
0026     if (cancelUrlMatch) {
0027         res.potentialAction = JsonLd.newObject("CancelAction")
0028         res.potentialAction.url = cancelUrlMatch[1]
0029     }
0030 
0031     res.reservationFor.location.address = address
0032     res.reservationFor.location.name = addr[1]
0033 
0034     // Both hh::mm and hh.mm are observed in the wild
0035     var dateTime = JsonLd.toDateTime(theDate + " " + theTime, "dd.MM.yyyy hh:mm", "de")
0036 
0037     if (isNaN(dateTime.getTime())) {
0038         dateTime = JsonLd.toDateTime(theDate + " " + theTime, "dd.MM.yyyy hh.mm", "de")
0039     }
0040 
0041     res.reservationFor.startDate = dateTime
0042 
0043     return res
0044 }