Commit f49bfa8f authored by Volker Krause's avatar Volker Krause
Browse files

Handle RCT2 Rail Pass Tickets (RPT)

This now produces correct titles and validity ranges for RCT2 Interrail
tickets.
parent 6128a08e
Pipeline #244531 passed with stage
in 10 minutes and 9 seconds
[
{
"@context": "http://schema.org",
"@type": "Rct2Ticket",
"firstDayOfValidity": "2022-10-30",
"outboundClass": "2",
"passengerName": "KONQI DRA.",
"title": " INTERRAIL",
"type": "http://schema.org/RailPass"
}
]
U_TLAY010425RCT200190019011900009INTERRAIL0039010400004NAME0053011900010KONQI DRA.01190119000000139010900009RESIDENCE0153011900007Germany0202010300003CIV020601040000499010239011200008PASS-/ID0253011900009*********0302010500005VALID030901230002330.10.2022 - 30.10.20220339011300013DATE OF BIRTH0353011000010**.**.****0614012600021INTERRAIL GLOBAL PASS066701010000121302010600005ADULT1315013700023ONLY VALID WITH PASS/ID1538010600006XXX007
......@@ -139,6 +139,7 @@ static constexpr const struct {
{ "cestovny listok", Rct2Ticket::Transport },
{ "reservation", Rct2Ticket::Reservation },
{ "reservierung", Rct2Ticket::Reservation },
{ "interrail", Rct2Ticket::RailPass },
};
Rct2Ticket::Type Rct2Ticket::type() const
......@@ -166,6 +167,11 @@ Rct2Ticket::Type Rct2Ticket::type() const
QString Rct2Ticket::title() const
{
// RPT has shorter title fields
if (type() == Rct2Ticket::RailPass) {
return d->layout.text(0, 18, 19, 1);
}
// somewhat standard compliant layout
if (d->layout.text(0, 15, 3, 1).trimmed().isEmpty()) {
return d->layout.text(0, 18, 33, 1).trimmed();
......@@ -200,12 +206,12 @@ static QString rct2Clean(const QString &s)
QString Rct2Ticket::outboundDepartureStation() const
{
return rct2Clean(d->layout.text(6, 13, 17, 1).trimmed());
return type() != RailPass ? rct2Clean(d->layout.text(6, 13, 17, 1).trimmed()) : QString();
}
QString Rct2Ticket::outboundArrivalStation() const
{
return rct2Clean(d->layout.text(6, 34, 17, 1).trimmed());
return type() != RailPass ? rct2Clean(d->layout.text(6, 34, 17, 1).trimmed()) : QString();
}
QString Rct2Ticket::outboundClass() const
......@@ -225,12 +231,12 @@ QDateTime Rct2Ticket::returnArrivalTime() const
QString Rct2Ticket::returnDepartureStation() const
{
return rct2Clean(d->layout.text(7, 13, 17, 1).trimmed());
return type() != RailPass ? rct2Clean(d->layout.text(7, 13, 17, 1).trimmed()) : QString();
}
QString Rct2Ticket::returnArrivalStation() const
{
return rct2Clean(d->layout.text(7, 34, 17, 1).trimmed());
return type() != RailPass ? rct2Clean(d->layout.text(7, 34, 17, 1).trimmed()) : QString();
}
QString Rct2Ticket::returnClass() const
......
......@@ -68,6 +68,7 @@ public:
TransportReservation, ///< Integration Reservation Ticket (IRT)
Reservation, ///< Reservation Only Document (RES)
Upgrade, ///< Update Document (UPG)
RailPass, ///< Rail Pass Ticket (RPT)
Unknown ///< ticket type could not be detected, or ticket type not supported yet
};
Q_ENUM(Type)
......
......@@ -219,6 +219,15 @@ QDateTime Uic9183Parser::validUntil() const
return dt;
}
// RCT2 RPT according to ERA TAP TSI Annex B.6
if (const auto rct2 = rct2Ticket(); rct2.isValid() && rct2.type() == Rct2Ticket::RailPass) {
const auto validityRange = ticketLayout().text(3, 1, 36, 1).trimmed();
const auto idx = std::max(validityRange.lastIndexOf(QLatin1Char(' ')), validityRange.lastIndexOf(QLatin1Char('-')));
if (idx > 0) {
return QDateTime(QDate::fromString(validityRange.mid(idx + 1), QStringLiteral("dd.MM.yyyy")), {23, 59, 59});
}
}
return {};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment