Commit 084cddf1 authored by Volker Krause's avatar Volker Krause
Browse files

NL CoronaCheck certificates specify no birth year, show that correctly

parent 6a5710cd
......@@ -34,7 +34,7 @@ ColumnLayout {
Kirigami.FormData.label: i18n("Name:")
}
QQC2.Label {
text: certificate.dateOfBirth.toLocaleDateString(Qt.locale(), Locale.ShortFormat)
text: Localizer.formatDate(certificate, "dateOfBirth")
visible: !isNaN(certificate.dateOfBirth.getTime())
Kirigami.FormData.label: i18n("Date of birth:")
}
......
......@@ -34,7 +34,7 @@ ColumnLayout {
Kirigami.FormData.label: i18n("Name:")
}
QQC2.Label {
text: certificate.dateOfBirth.toLocaleDateString(Qt.locale(), Locale.ShortFormat)
text: Localizer.formatDate(certificate, "dateOfBirth")
visible: !isNaN(certificate.dateOfBirth.getTime())
Kirigami.FormData.label: i18n("Date of birth:")
}
......
......@@ -37,7 +37,7 @@ ColumnLayout {
Kirigami.FormData.label: i18n("Name:")
}
QQC2.Label {
text: certificate.dateOfBirth.toLocaleDateString(Qt.locale(), Locale.ShortFormat)
text: Localizer.formatDate(certificate, "dateOfBirth")
visible: !isNaN(certificate.dateOfBirth.getTime())
Kirigami.FormData.label: i18n("Date of birth:")
}
......
......@@ -134,6 +134,19 @@ QString Localizer::formatTime(const QVariant &obj, const QString &propertyName)
return s;
}
QString Localizer::formatDate(const QVariant &obj, const QString &propertyName) const
{
const auto dt = JsonLdDocument::readProperty(obj, propertyName.toUtf8().constData()).toDate();
if (!dt.isValid()) {
return {};
}
if (dt.year() <= 1900) { // no year specified
return dt.toString(QStringLiteral("dd MMMM")); // TODO i18n in master
}
return QLocale().toString(dt, QLocale::ShortFormat);
}
QString Localizer::formatDateTime(const QVariant& obj, const QString& propertyName) const
{
const auto dt = JsonLdDocument::readProperty(obj, propertyName.toUtf8().constData()).toDateTime();
......
......@@ -26,6 +26,7 @@ public:
Q_INVOKABLE QString countryFlag(const QString &isoCode) const;
Q_INVOKABLE QString formatAddress(const QVariant &obj) const;
Q_INVOKABLE QString formatTime(const QVariant &obj, const QString &propertyName) const;
Q_INVOKABLE QString formatDate(const QVariant &obj, const QString &propertyName) const;
Q_INVOKABLE QString formatDateTime(const QVariant &obj, const QString &propertyName) const;
Q_INVOKABLE QString formatDuration(int seconds) const;
Q_INVOKABLE QString formatDistance(int meter) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment