Commit 3bf71304 authored by Volker Krause's avatar Volker Krause
Browse files

Display validity interval for tickets and program memberships

parent be8c44be
......@@ -103,6 +103,16 @@ Kirigami.ScrollablePage {
text: programMembership.membershipNumber
visible: programMembership.membershipNumber !== ""
}
QQC2.Label {
Kirigami.FormData.label: i18n("Valid from:")
text: Localizer.formatDateOrDateTimeLocal(programMembership, "validFrom")
visible: text !== ""
}
QQC2.Label {
Kirigami.FormData.label: i18n("Valid until:")
text: Localizer.formatDateOrDateTimeLocal(programMembership, "validUntil")
visible: text !== ""
}
}
}
}
......@@ -89,7 +89,6 @@ Kirigami.ScrollablePage {
Kirigami.Separator {
Kirigami.FormData.label: i18n("Ticket")
Kirigami.FormData.isSection: true
visible: nameLabel.visible || numberLabel.visible || classLabel.visible
}
QQC2.Label {
id: nameLabel
......@@ -97,6 +96,16 @@ Kirigami.ScrollablePage {
text: ticket.underName.name
visible: ticket.underName.name !== ""
}
QQC2.Label {
Kirigami.FormData.label: i18n("Valid from:")
text: Localizer.formatDateOrDateTimeLocal(ticket, "validFrom")
visible: text !== ""
}
QQC2.Label {
Kirigami.FormData.label: i18n("Valid until:")
text: Localizer.formatDateOrDateTimeLocal(ticket, "validUntil")
visible: text !== ""
}
QQC2.Label {
id: numberLabel
Kirigami.FormData.label: i18n("Number:")
......
......@@ -148,6 +148,21 @@ QString Localizer::formatDateTime(const QVariant& obj, const QString& propertyNa
return s;
}
QString Localizer::formatDateOrDateTimeLocal(const QVariant& obj, const QString& propertyName) const
{
const auto dt = JsonLdDocument::readProperty(obj, propertyName.toUtf8().constData()).toDateTime();
if (!dt.isValid()) {
return {};
}
// detect likely date-only values
if (dt.timeSpec() == Qt::LocalTime && (dt.time() == QTime{0, 0, 0} || dt.time() == QTime{23, 59, 59})) {
return QLocale().toString(dt.date(), QLocale::ShortFormat);
}
return QLocale().toString(dt.toLocalTime(), QLocale::ShortFormat);
}
QString Localizer::formatDuration(int seconds) const
{
if (seconds < 0) {
......
......@@ -23,6 +23,8 @@ public:
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;
/** Auto-detect date or date/time, and convert to local time zone. */
Q_INVOKABLE QString formatDateOrDateTimeLocal(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