feat: introduce Utils.formatDateTime

We already have a utility function to format time, this one formats date + time
and is used in status updates as well as channel lists.
This commit is contained in:
Pascal Precht 2020-12-22 11:22:04 +01:00 committed by Iuri Matias
parent 0767ce2443
commit eca5622439
4 changed files with 40 additions and 44 deletions

View File

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

View File

@ -38,6 +38,7 @@ Rectangle {
ChatTime {
id: chatTime
formatDateTime: true
visible: chatName.visible
anchors.verticalCenter: chatName.verticalCenter
anchors.left: chatName.right

View File

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

View File

@ -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<assets.rowCount(); i++) {
const symbol = assets.rowData(i, "symbol")