fix: fix timestamp formatting in chat list

Closes #396
This commit is contained in:
Pascal Precht 2020-06-24 15:04:29 +02:00 committed by Iuri Matias
parent db35bce531
commit 6a49070431
1 changed files with 19 additions and 1 deletions

View File

@ -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