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 QMap<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 formatInput(QString user_input, Opl::Date::ADateFormat format);
34 
38  inline static QString toString(const QDate &date, Opl::Date::ADateFormat format = Opl::Date::ADateFormat::ISODate)
39  {
40  return date.toString(ADATEFORMATSMAP.value(format));
41  };
42 
43  static const QStringList& getDisplayNames();
44 
45  static const QString getFormatString(Opl::Date::ADateFormat format);
46 
47 };
48 
49 #endif // ADATE_H
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:38
ADate::formatInput
static QDate formatInput(QString user_input, Opl::Date::ADateFormat format)
formatInput takes a user-provided input and tries to convert it to a QDate.
Definition: adate.cpp:3
ADate
The ADate class is responsible for input/output of Dates and handling the different Date Formats.
Definition: adate.h:27