[TD]respect locale for date autofill (#18132)

* [TD]respect locale for date autofill

* [TD]fix merge conflict

* Apply suggestions from code review

---------

Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
WandererFan
2024-12-13 12:07:54 -05:00
committed by GitHub
parent d835cde3a5
commit 8b7cbae43b
6 changed files with 344 additions and 307 deletions

View File

@@ -37,6 +37,7 @@
#include "DrawTemplatePy.h"
#include "DrawPage.h"
#include "DrawUtil.h"
#include "Preferences.h"
using namespace TechDraw;
@@ -129,6 +130,7 @@ std::pair<int, int> DrawTemplate::getPageNumbers() const
//! get replacement values from document
QString DrawTemplate::getAutofillValue(const QString &id) const
{
constexpr int ISODATELENGTH {10};
auto doc = getDocument();
if (!doc) {
return QString();
@@ -142,8 +144,14 @@ QString DrawTemplate::getAutofillValue(const QString &id) const
}
// date
else if (id.compare(QString::fromUtf8(Autofill::Date)) == 0) {
auto timeLocale = std::setlocale(LC_TIME, nullptr);
QDateTime date = QDateTime::currentDateTime();
return date.toString(QLocale().dateFormat(QLocale::ShortFormat));
if (Preferences::enforceISODate()) {
auto rawDate = date.toString(Qt::ISODate);
return rawDate.left(ISODATELENGTH);
}
auto qTimeLocale = QString::fromUtf8(timeLocale);
return date.toString(QLocale(qTimeLocale).dateFormat(QLocale::ShortFormat));
}
// organization ( also organisation/owner/company )
else if (id.compare(QString::fromUtf8(Autofill::Organization)) == 0 ||