From 19b9c6e1643e530424afb4f8f3c21464d3a6b936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Thu, 8 Sep 2022 10:55:27 +0200 Subject: [PATCH] fix: StatusDateGroupLabel doesn't support i18n and has no year - fix evaluating "Today" and "Yesterday"; can't just compare the two Date objects, the timestamp will always differ so need to compare year/month/day only - best attempt to have the month translated, and year added if they differ (until Qt6 at least, left a TODO) Closes #843 --- .../Components/StatusDateGroupLabel.qml | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/ui/StatusQ/src/StatusQ/Components/StatusDateGroupLabel.qml b/ui/StatusQ/src/StatusQ/Components/StatusDateGroupLabel.qml index e933792cdf..c97394cd91 100644 --- a/ui/StatusQ/src/StatusQ/Components/StatusDateGroupLabel.qml +++ b/ui/StatusQ/src/StatusQ/Components/StatusDateGroupLabel.qml @@ -18,37 +18,25 @@ StatusBaseText { if (previousMessageIndex === -1) return ""; - const now = new Date() - const yesterday = new Date() - yesterday.setDate(now.getDate()-1) - const currentMsgDate = new Date(messageTimestamp); const prevMsgDate = new Date(previousMessageTimestamp); if (!!prevMsgDate && currentMsgDate.getDay() === prevMsgDate.getDay()) return ""; - if (now == currentMsgDate) + const now = new Date(); + if (now.getFullYear() == currentMsgDate.getFullYear() && now.getMonth() == currentMsgDate.getMonth() && now.getDate() == currentMsgDate.getDate()) return qsTr("Today"); - if (yesterday == currentMsgDate) + const yesterday = new Date(); + yesterday.setDate(now.getDate()-1); + if (yesterday.getFullYear() == currentMsgDate.getFullYear() && yesterday.getMonth() == currentMsgDate.getMonth() && yesterday.getDate() == currentMsgDate.getDate()) return qsTr("Yesterday"); - const monthNames = [ - qsTr("January"), - qsTr("February"), - qsTr("March"), - qsTr("April"), - qsTr("May"), - qsTr("June"), - qsTr("July"), - qsTr("August"), - qsTr("September"), - qsTr("October"), - qsTr("November"), - qsTr("December") - ]; - - return monthNames[currentMsgDate.getMonth()] + ", " + currentMsgDate.getDate(); + // FIXME Qt6: replace with Intl.DateTimeFormat + const monthName = Qt.locale().standaloneMonthName(currentMsgDate.getMonth(), Locale.LongFormat) + if (now.getFullYear() > currentMsgDate.getFullYear()) + return "%1 %2, %3".arg(monthName).arg(currentMsgDate.getDate()).arg(currentMsgDate.getFullYear()) + return "%1, %2".arg(monthName).arg(currentMsgDate.getDate()) } }