7#include "iatabcbpsections.h"
8#include "iatabcbpconstants_p.h"
13using namespace KItinerary::IataBcbpConstants;
15QString IataBcbpSectionBase::readString(
int offset,
int length)
const
17 if (m_data.size() >= offset + length) {
18 return m_data.mid(offset, length).trimmed().toString();
23int IataBcbpSectionBase::readNumericValue(
int offset,
int length,
int base)
const
25 if (m_data.size() >= offset + length) {
26 return m_data.mid(offset, length).toInt(
nullptr, base);
32IataBcbpUniqueMandatorySection::IataBcbpUniqueMandatorySection(QStringView data)
37bool IataBcbpUniqueMandatorySection::isValid()
const
39 const auto legCount = numberOfLegs();
40 return legCount >= 1 && legCount <= 4;
43IataBcbpUniqueConditionalSection::IataBcbpUniqueConditionalSection(QStringView data)
45 if (data.
size() < MinimumUniqueConditionalSize) {
49 m_data = data.
left(MinimumUniqueConditionalSize + fieldSize());
52bool IataBcbpUniqueConditionalSection::isValid()
const
54 if (m_data.size() >= 11) {
56 if (std::any_of(m_data.begin() + 8, m_data.begin() + 11, [](
auto c) { return !c.isDigit() && c !=
' '_L1; }) || dayOfIssue() > 366) {
63QDate IataBcbpUniqueConditionalSection::dateOfIssue(
const QDateTime &contextDate)
const
65 const auto day = dayOfIssue() - 1;
66 if (m_data.size() < 11 || day < 0) {
70 const auto year = contextDate.
date().
year() - contextDate.
date().
year() % 10 + yearOfIssue();
71 const auto d = QDate(year, 1, 1).addDays(day);
73 if (year > contextDate.
date().
year()) {
74 return QDate(year - 10, 1, 1).addDays(day);
79IataBcbpRepeatedMandatorySection::IataBcbpRepeatedMandatorySection(QStringView data)
84static bool isValidAirportCode(QStringView s)
86 return std::all_of(s.
begin(), s.
end(), [](
const QChar c) { return c.isLetter() && c.isUpper(); });
89bool IataBcbpRepeatedMandatorySection::isValid()
const
91 if (m_data.size() < RepeatedMandatoryMinimalViableSize) {
95 return isValidAirportCode(m_data.mid(7, 3))
96 && isValidAirportCode(m_data.mid(10, 3))
97 && std::all_of(m_data.begin() + 21, m_data.begin() + 24, [](
auto c) { return c.isDigit() || c ==
' '_L1; })
98 && dayOfFlight() <= 366;
103 const auto day = dayOfFlight() - 1;
108 if (d < contextDate.
date()) {
114IataBcbpRepeatedConditionalSection::IataBcbpRepeatedConditionalSection(
QStringView data)
116 if (data.
size() < 2) {
120 m_data = data.
left(conditionalFieldSize() + 2);
123IataBcbpSecuritySection::IataBcbpSecuritySection(QStringView data)
125 if (data.
size() < MinimumSecuritySectionSize) {
129 m_data = data.
left(size() + MinimumSecuritySectionSize);
132#include "moc_iatabcbpsections.cpp"
Q_INVOKABLE QDate dateOfFlight(const QDateTime &contextDate=QDateTime::currentDateTime()) const
Date of the flight.
Classes for reservation/travel data models, data extraction and data augmentation.
QDate addDays(qint64 ndays) const const
QStringView left(qsizetype length) const const
const_iterator begin() const const
const_iterator end() const const
qsizetype size() const const