diff --git a/DCPlugin.pro b/DCPlugin.pro index 2615d7a..6a13db3 100644 --- a/DCPlugin.pro +++ b/DCPlugin.pro @@ -88,7 +88,8 @@ HEADERS += \ src/ATBAPP/support/JSON.h \ src/ATBAPP/support/PTUSystem.h \ src/ATBAPP/support/PersistentData.h \ - src/ATBAPP/support/Ticket.h + src/ATBAPP/support/Ticket.h \ + src/ATBAPP/support/TicketUtils.h SOURCES += \ src/ATBAPP/ATBHealthEvent.cpp \ @@ -101,7 +102,8 @@ SOURCES += \ src/ATBAPP/support/JSON.cpp \ src/ATBAPP/support/PTUSystem.cpp \ src/ATBAPP/support/PersistentData.cpp \ - src/ATBAPP/support/Ticket.cpp + src/ATBAPP/support/Ticket.cpp \ + src/ATBAPP/support/TicketUtils.cpp DISTFILES += \ generate-version.sh diff --git a/src/ATBAPP/support/TicketUtils.cpp b/src/ATBAPP/support/TicketUtils.cpp new file mode 100644 index 0000000..9d39777 --- /dev/null +++ b/src/ATBAPP/support/TicketUtils.cpp @@ -0,0 +1,26 @@ +#include "TicketUtils.h" + +#include +#include + +TicketUtils::TicketUtils(QObject *parent) : QObject(parent) +{ + +} + + +QString TicketUtils::getLocaleDateString(const QLocale & qLocale, const QDate & qDate) +{ + QString dateString; + + if (qLocale.language() == QLocale::Lithuanian) { + // QLocale::ShortFormat produces date string: "yyyy-mm-dd" ... + // this is to long for the printer. + dateString = qDate.toString("YY-MM-dd"); + } + else { + dateString = qLocale.toString(qDate, QLocale::ShortFormat); + } + + return dateString; +} diff --git a/src/ATBAPP/support/TicketUtils.h b/src/ATBAPP/support/TicketUtils.h new file mode 100644 index 0000000..4759713 --- /dev/null +++ b/src/ATBAPP/support/TicketUtils.h @@ -0,0 +1,34 @@ +#ifndef TICKETUTILS_H +#define TICKETUTILS_H + +#include + +class TicketUtils : public QObject +{ + Q_OBJECT +public: + explicit TicketUtils(QObject *parent = nullptr); + + /** + * @brief getLocaleDateString + * @param qLocale + * @param qDate + * @return a localized date string short format + * + * Note QLocale::ShortFormat does not result to the + * string we need for ticket printing therefore this + * helper method was created. + * + * e.g. using Lithuanian (lt_LT) we get a date in short format: + * "2024-08-08" unfortunately this is to long, we need + * the year with only two digits. + * e.g. in German (de_DE) it is enought: "08.08.24" + * + */ + static QString getLocaleDateString(const QLocale &qLocale, const QDate &qDate); + +signals: + +}; + +#endif // TICKETUTILS_H