Commit 78af4036 authored by Volker Krause's avatar Volker Krause
Browse files

Compute validity dates from SSBv2 data as well

Similar to what we have for the other versions already.
parent 6c78c19a
......@@ -42,6 +42,36 @@ bool SSBv2Ticket::maybeSSB(const QByteArray& data)
return (data.at(0) >> 4) == SSBV2_VERSION;
}
QDate SSBv2Ticket::firstDayOfValidity(const QDateTime &contextDate) const
{
if (!isValid() || firstDayOfValidityDay() > 366) {
return {};
}
QDate dt(contextDate.date().year(), 1, 1);
dt = dt.addDays(firstDayOfValidityDay() - 1);
if (dt < contextDate.date()) {
QDate dt(contextDate.date().year() + 1, 1, 1);
dt = dt.addDays(firstDayOfValidityDay() - 1);
}
return dt;
}
QDate SSBv2Ticket::lastDayOfValidity(const QDateTime &contextDate) const
{
if (!isValid() || lastDayOfValidityDay() > 366) {
return {};
}
QDate dt(contextDate.date().year(), 1, 1);
dt = dt.addDays(lastDayOfValidityDay() - 1);
if (dt < contextDate.date() || dt < firstDayOfValidity()) {
QDate dt(contextDate.date().year() + 1, 1, 1);
dt = dt.addDays(firstDayOfValidityDay() - 1);
}
return dt;
}
QByteArray SSBv2Ticket::rawData() const
{
return m_data;
......
......@@ -9,6 +9,7 @@
#include "kitinerary_export.h"
#include "ssbticketbase.h"
#include <QDateTime>
#include <QMetaType>
namespace KItinerary {
......@@ -26,8 +27,8 @@ class KITINERARY_EXPORT SSBv2Ticket : protected SSBTicketBase
SSB_NUM_PROPERTY(numberOfTickets, 23, 6)
SSB_NUM_PROPERTY(numberOfAdultPassengers, 29, 7)
SSB_NUM_PROPERTY(numberOfChildPassengers, 36, 7)
SSB_NUM_PROPERTY(firstDayOfValidity, 43, 9)
SSB_NUM_PROPERTY(lastDayOfValidity, 52, 9)
SSB_NUM_PROPERTY(firstDayOfValidityDay, 43, 9)
SSB_NUM_PROPERTY(lastDayOfValidityDay, 52, 9)
SSB_NUM_PROPERTY(customerNumberType, 61, 1)
SSB_LONG_PROPERTY(customerNumber, 62, 47)
SSB_NUM_PROPERTY(departureStationType, 109, 1)
......@@ -61,6 +62,11 @@ public:
/** Returns @c true if this is a valid SSB ticket. */
bool isValid() const;
/** First day of validity. */
Q_INVOKABLE QDate firstDayOfValidity(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
/** Last day of validity. */
Q_INVOKABLE QDate lastDayOfValidity(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
/** Raw barcode data. */
QByteArray rawData() const;
......
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