From 0981ffdc181d82368650428f95ef73b838e57c03 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 18 May 2022 10:49:48 +0200 Subject: [PATCH] fix(@desktop/chat): timestamps are constant Fixes #5803 --- .../shared/panels/chat/ChatTimePanel.qml | 2 +- ui/imports/utils/Utils.qml | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ui/imports/shared/panels/chat/ChatTimePanel.qml b/ui/imports/shared/panels/chat/ChatTimePanel.qml index 5122a39eef..a9f66e031d 100644 --- a/ui/imports/shared/panels/chat/ChatTimePanel.qml +++ b/ui/imports/shared/panels/chat/ChatTimePanel.qml @@ -12,7 +12,7 @@ StyledText { property string timestamp color: Style.current.secondaryText - text: Utils.formatShortTime(chatTime.timestamp, RootStore.accountSensitiveSettings.is24hTimeFormat) + text: Utils.formatShortTime(parseInt(chatTime.timestamp, 10), RootStore.accountSensitiveSettings.is24hTimeFormat) font.pixelSize: Style.current.asideTextFontSize StatusQ.StatusToolTip { diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index 8b41132431..7f9ebca451 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -225,13 +225,21 @@ QtObject { return Qt.hsla(color.hslHue, color.hslSaturation, color.hslLightness, alpha) } + function checkTimestamp(value, errorLocation) { + if(Number.isInteger(value) && value > 0) { + return true; + } + console.error(qsTr("timestamp must be type of int and greater than 0 (%1)").arg(errorLocation)); + return false; + } + function formatTime(value, is24hTimeFormat) { const format24h = "hh:mm:ss t" const format12h = "h:mm:ss AP t" const currentTimeFormat = is24hTimeFormat ? format24h : format12h - return !!value ? Qt.formatTime(new Date(), currentTimeFormat) : - Qt.formatTime(new Date(value), currentTimeFormat) + return checkTimestamp(value, "formatTime") ? Qt.formatTime(new Date(value), currentTimeFormat) : + Qt.formatTime(new Date(), currentTimeFormat) } function formatShortTime(value, is24hTimeFormat) { @@ -239,8 +247,8 @@ QtObject { const format12h = "h:mm AP" const currentTimeFormat = is24hTimeFormat ? format24h : format12h - return !!value ? Qt.formatTime(new Date(), currentTimeFormat) : - Qt.formatTime(new Date(value), currentTimeFormat) + return checkTimestamp(value, "formatShortTime") ? Qt.formatTime(new Date(value), currentTimeFormat) : + Qt.formatTime(new Date(), currentTimeFormat) } function formatShortDateStr(longStr) { @@ -301,8 +309,8 @@ QtObject { const formatDDMMYY = "dddd d MMMM yyyy" const formatMMDDYY = "dddd, MMMM d, yyyy" const currentFormat = isDDMMYYDateFormat ? formatDDMMYY : formatMMDDYY - return !value ? Qt.formatDate(new Date(), currentFormat) : - Qt.formatDate(new Date(value), currentFormat) + return checkTimestamp(value, "formatLongDate") ? Qt.formatDate(new Date(value), currentFormat) : + Qt.formatDate(new Date(), currentFormat) } function formatLongDateTime(value, isDDMMYYDateFormat, is24hTimeFormat) { @@ -312,8 +320,8 @@ QtObject { const format12h = "h:mm:ss AP t" const currentDateFormat = isDDMMYYDateFormat ? formatDDMMYY : formatMMDDYY const currentTimeFormat = is24hTimeFormat ? format24h : format12h - return !!value ? Qt.formatDateTime(new Date(), currentDateFormat + " " + currentTimeFormat) : - Qt.formatDateTime(new Date(value), currentDateFormat + " " + currentTimeFormat) + return checkTimestamp(value, "formatLongDateTime") ? Qt.formatDateTime(new Date(value), currentDateFormat + " " + currentTimeFormat) : + Qt.formatDateTime(new Date(), currentDateFormat + " " + currentTimeFormat) } // WARN: It is not used!! TO BE REMOVE??