From 6a49070431311cb76962794ffcd40f14fba6ad49 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Wed, 24 Jun 2020 15:04:29 +0200 Subject: [PATCH] fix: fix timestamp formatting in chat list Closes #396 --- .../Chat/ContactsColumn/Channel.qml | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml b/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml index 57877783ca..8832127752 100644 --- a/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml +++ b/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml @@ -89,7 +89,25 @@ Rectangle { } StyledText { id: contactTime - text: wrapper.timestamp + text: { + let now = new Date() + let yesterday = new Date() + yesterday.setDate(now.getDate()-1) + let messageDate = new Date(Math.floor(wrapper.timestamp)) + let lastWeek = new Date() + lastWeek.setDate(now.getDate()-7) + + if (now.toDateString() == messageDate.toDateString()) { + return messageDate.getHours() + ":" + (messageDate.getMinutes() < 10 ? "0" + messageDate.getMinutes() : messageDate.getMinutes()) + } else if (yesterday.toDateString() == messageDate.toDateString()) { + return qsTr("Yesterday") + } else if (lastWeek.getTime() < messageDate.getTime()) { + let days = [qsTr('Sunday'), qsTr('Monday'), qsTr('Tuesday'), qsTr('Wednesday'), qsTr('Thursday'), qsTr('Friday'), qsTr('Saturday')]; + return days[messageDate.getDay()]; + } else { + return messageDate.getMonth()+1+"/"+messageDate.getDay()+"/"+messageDate.getFullYear() + } + } anchors.right: parent.right anchors.rightMargin: Theme.padding anchors.top: parent.top