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::DateFormat, QString> ADATEFORMATSMAP = {
10  {OPL::DateFormat::ISODate, ISO},
11  {OPL::DateFormat::DE, DE },
12  {OPL::DateFormat::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::DateFormat format);
34 
35  static void tryToFix(QString &io_user_input, OPL::DateFormat format);
36 
40  static void padCentury(QString &io_user_input, OPL::DateFormat format);
41 
45  static void padZeroes(QString &io_user_input);
46 
47  static void addSeperators(QString &io_user_input, const OPL::DateFormat &format);
48 
49  static bool containsSeperator(const QString &user_input);
50 
54  inline static QString toString(const QDate &date, OPL::DateFormat format = OPL::DateFormat::ISODate)
55  {
56  return date.toString(ADATEFORMATSMAP.value(format));
57  };
58 
59  static const QStringList& getDisplayNames();
60 
61  static const QString getFormatString(OPL::DateFormat format);
62 
67  static const QString currentDate();
68 
69 };
70 
71 #endif // ADATE_H
The ADate class is responsible for input/output of Dates and handling the different Date Formats.
Definition: adate.h:27
static void padCentury(QString &io_user_input, OPL::DateFormat format)
padCentury adds the century to a date where it was omitted
Definition: adate.cpp:36
static QDate parseInput(QString &io_user_input, OPL::DateFormat format)
takes a user-provided input and tries to convert it to a (valid) QDate.
Definition: adate.cpp:3
static const QString currentDate()
today Returns a string containing the current date in ISO format
Definition: adate.cpp:135
static QString toString(const QDate &date, OPL::DateFormat format=OPL::DateFormat::ISODate)
Reimplements QDate::toString to accept OPL::Date::ADateFormat enums.
Definition: adate.h:54
static void padZeroes(QString &io_user_input)
pads a user-provided date string with 0s to facilitate conversion to QDate
Definition: adate.cpp:67
DateFormat
ADateFormats enumerates the accepted date formats for QDateEdits.
Definition: opl.h:92