mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-24 05:21:58 +00:00
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:
parent
0767ce2443
commit
eca5622439
@ -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
|
||||
|
@ -38,6 +38,7 @@ Rectangle {
|
||||
|
||||
ChatTime {
|
||||
id: chatTime
|
||||
formatDateTime: true
|
||||
visible: chatName.visible
|
||||
anchors.verticalCenter: chatName.verticalCenter
|
||||
anchors.left: chatName.right
|
||||
|
@ -119,42 +119,7 @@ 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()
|
||||
}
|
||||
}
|
||||
text: Utils.formatDateTime(wrapper.timestamp)
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: !isCompact ? Style.current.padding : Style.current.smallPadding
|
||||
anchors.top: !isCompact ? parent.top : undefined
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user