status-desktop/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/DateGroup.qml

65 lines
2.0 KiB
QML

import QtQuick 2.3
import "../../../../../shared"
import "../../../../../imports"
StyledText {
id: dateGroupLbl
font.pixelSize: 13
color: Style.current.secondaryText
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
text: {
if (prevMessageIndex == -1) return ""; // identifier
let now = new Date()
let yesterday = new Date()
yesterday.setDate(now.getDate()-1)
var currentMsgDate = new Date(parseInt(timestamp, 10));
var prevMsgDate = prevMsgTimestamp === "" ? new Date(0) : new Date(parseInt(prevMsgTimestamp, 10));
if (currentMsgDate.getDay() === prevMsgDate.getDay()) {
return ""
}
if (now.toDateString() === currentMsgDate.toDateString()) {
//% "Today"
return qsTrId("today")
} else if (yesterday.toDateString() === currentMsgDate.toDateString()) {
//% "Yesterday"
return qsTrId("yesterday")
} else {
const monthNames = [
//% "January"
qsTrId("january"),
//% "February"
qsTrId("february"),
//% "March"
qsTrId("march"),
//% "April"
qsTrId("april"),
//% "May"
qsTrId("may"),
//% "June"
qsTrId("june"),
//% "July"
qsTrId("july"),
//% "August"
qsTrId("august"),
//% "September"
qsTrId("september"),
//% "October"
qsTrId("october"),
//% "November"
qsTrId("november"),
//% "December"
qsTrId("december")
];
return monthNames[currentMsgDate.getMonth()] + ", " + currentMsgDate.getDate()
}
}
visible: text !== ""
anchors.top: parent.top
anchors.topMargin: this.visible ? 20 : 0
}