diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml index 004b6dee04..c939d3e8cc 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml @@ -3,10 +3,11 @@ import "../../../../../shared" import "../../../../../imports" StyledTextEdit { + property bool formatDateTime: false id: chatTime visible: isMessage color: Style.current.darkGrey - text: Utils.formatTime(timestamp) + text: formatDateTime ? Utils.formatDateTime(timestamp) : Utils.formatTime(timestamp) font.pixelSize: Style.current.asideTextFontSize readOnly: true selectByMouse: true diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/StatusUpdate.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/StatusUpdate.qml index 92ed58b778..d7552acc5b 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/StatusUpdate.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/StatusUpdate.qml @@ -38,6 +38,7 @@ Rectangle { ChatTime { id: chatTime + formatDateTime: true visible: chatName.visible anchors.verticalCenter: chatName.verticalCenter anchors.left: chatName.right diff --git a/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml b/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml index 0ba0658b09..38a6049ad9 100644 --- a/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml +++ b/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml @@ -119,49 +119,14 @@ Rectangle { StyledText { id: contactTime - 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) - - let minutes = messageDate.getMinutes(); - let hours = messageDate.getHours(); - - if (now.toDateString() === messageDate.toDateString()) { - return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) - } else if (yesterday.toDateString() === messageDate.toDateString()) { - //% "Yesterday" - return qsTrId("yesterday") - } else if (lastWeek.getTime() < messageDate.getTime()) { - //% "Sunday" - let days = [qsTrId("sunday"), - //% "Monday" - qsTrId("monday"), - //% "Tuesday" - qsTrId("tuesday"), - //% "Wednesday" - qsTrId("wednesday"), - //% "Thursday" - qsTrId("thursday"), - //% "Friday" - qsTrId("friday"), - //% "Saturday" - qsTrId("saturday")]; - return days[messageDate.getDay()]; - } else { - return messageDate.getMonth()+1+"/"+messageDate.getDate()+"/"+messageDate.getFullYear() - } - } - anchors.right: parent.right - anchors.rightMargin: !isCompact ? Style.current.padding : Style.current.smallPadding - anchors.top: !isCompact ? parent.top : undefined - anchors.topMargin: !isCompact ? Style.current.smallPadding : 0 - anchors.verticalCenter: !isCompact ? undefined : parent.verticalCenter - font.pixelSize: 11 - color: Style.current.darkGrey + text: Utils.formatDateTime(wrapper.timestamp) + anchors.right: parent.right + anchors.rightMargin: !isCompact ? Style.current.padding : Style.current.smallPadding + anchors.top: !isCompact ? parent.top : undefined + anchors.topMargin: !isCompact ? Style.current.smallPadding : 0 + anchors.verticalCenter: !isCompact ? undefined : parent.verticalCenter + font.pixelSize: 11 + color: Style.current.darkGrey } Rectangle { id: contactNumberChatsCircle diff --git a/ui/imports/Utils.qml b/ui/imports/Utils.qml index 186eec74ae..a0a227f024 100644 --- a/ui/imports/Utils.qml +++ b/ui/imports/Utils.qml @@ -130,6 +130,35 @@ QtObject { return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) } + function formatDateTime(timestamp) { + let now = new Date() + let yesterday = new Date() + yesterday.setDate(now.getDate()-1) + let messageDate = new Date(Math.floor(timestamp)) + let lastWeek = new Date() + lastWeek.setDate(now.getDate()-7) + + let minutes = messageDate.getMinutes(); + let hours = messageDate.getHours(); + + if (now.toDateString() === messageDate.toDateString()) { + return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + } 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.getDate()+"/"+messageDate.getFullYear() + } + } + function findAssetBySymbol(assets, symbolToFind) { for(var i=0; i