| openPilotLog

adate.h
1 #ifndef ADATE_H
2 #define ADATE_H
3 #include "src/opl.h"
4
5 const static auto ISO = QStringLiteral("yyyy-MM-dd");
6 const static auto DE = QStringLiteral("dd.MM.yyyy");
7 const static auto EN = QStringLiteral("MM/dd/yyyy");
8
9 const static QHash<Opl::Date::ADateFormat, QString> ADATEFORMATSMAP = {
10 {Opl::Date::ADateFormat::ISODate, ISO},
11 {Opl::Date::ADateFormat::DE, DE },
12 {Opl::Date::ADateFormat::EN, EN },
13
14 };
15
16 const static QStringList DISPLAY_NAMES = {
17 QStringLiteral("ISO 8601: yyyy-MM-dd"),
18 QStringLiteral("DE: dd.MM.yyyy"),
19 QStringLiteral("EN: MM/dd/yyyy")
20 };
21
26 class ADate
27 {
28 public:
33 static QDate parseInput(QString &io_user_input, Opl::Date::ADateFormat format);
34
35 static void tryToFix(QString &io_user_input, Opl::Date::ADateFormat format);
36
40 static void padCentury(QString &io_user_input, Opl::Date::ADateFormat format);
41
45 static void padZeroes(QString &io_user_input);
46
47 static void addSeperators(QString &io_user_input, const Opl::Date::ADateFormat &format);
48
49 static bool containsSeperator(const QString &user_input);
50
54 inline static QString toString(const QDate &date, Opl::Date::ADateFormat format = Opl::Date::ADateFormat::ISODate)
55 {
56 return date.toString(ADATEFORMATSMAP.value(format));
57 };
58
59 static const QStringList& getDisplayNames();
60
61 static const QString getFormatString(Opl::Date::ADateFormat format);
62
63 };
64
65 #endif // ADATE_H
ADate
The ADate class is responsible for input/output of Dates and handling the different Date Formats.
Definition: adate.h:27
ADate::padCentury
static void padCentury(QString &io_user_input, Opl::Date::ADateFormat format)
padCentury adds the century to a date where it was omitted
Definition: adate.cpp:36
ADate::padZeroes
static void padZeroes(QString &io_user_input)
pads a user-provided date string with 0s to facilitate conversion to QDate
Definition: adate.cpp:67
ADate::parseInput
static QDate parseInput(QString &io_user_input, Opl::Date::ADateFormat format)
takes a user-provided input and tries to convert it to a (valid) QDate.
Definition: adate.cpp:3
ADate::toString
static QString toString(const QDate &date, Opl::Date::ADateFormat format=Opl::Date::ADateFormat::ISODate)
Reimplements QDate::toString to accept Opl::Date::ADateFormat enums.
Definition: adate.h:54