aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.cpp')
-rw-r--r--src/config.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 4f5831c..9e223f8 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -23,7 +23,9 @@
// so this reports the same numbers rather than keeping a second copy.
#include "messageview.h"
+#include <QDateTime>
#include <QFileInfo>
+#include <QLocale>
#include <QSettings>
#include <QStandardPaths>
@@ -146,6 +148,29 @@ void Config::load(const QString &path)
}
}
+ // Absent or empty means the system locale's short format, which is what
+ // every other application on the desktop shows. Only a non-empty pattern is
+ // validated, and a rejected one falls back to that same default.
+ const QString dateFormat =
+ settings.value(QStringLiteral("date_format")).toString().trimmed();
+ if (!dateFormat.isEmpty()) {
+ // QDateTime::toString() with a pattern carrying no date or time field
+ // returns the pattern verbatim rather than failing, so "banana" would
+ // print "banana" on every card. Formatting two DIFFERENT instants and
+ // comparing is what catches that: a pattern with any real field gives
+ // two different strings, one with none gives the same string twice.
+ const QDateTime a(QDate(2028, 12, 28), QTime(22, 58));
+ const QDateTime b(QDate(2019, 1, 3), QTime(4, 5));
+ const QLocale locale = QLocale::system();
+ if (locale.toString(a, dateFormat) == locale.toString(b, dateFormat)) {
+ addProblem(QStringLiteral("Date format '%1' contains no date or "
+ "time field; using the system format.")
+ .arg(dateFormat));
+ } else {
+ m_dateFormat = dateFormat;
+ }
+ }
+
// Absent is silent, the default being 2000. Present but unparseable warns,
// for the same reason message_zoom does: the user asked for something and
// is not getting it.