Move room date formatting logic to utils function

This commit is contained in:
miruka 2020-06-24 08:14:54 -04:00
parent 2d8dbb172d
commit b9f8740954
2 changed files with 20 additions and 16 deletions

View File

@ -60,22 +60,7 @@ HTile {
TitleRightInfoLabel {
tile: room
color: theme.mainPane.listView.room.lastEventDate
text: {
model.last_event_date < new Date(1) ?
"" :
// e.g. "03:24"
utils.dateIsToday(model.last_event_date) ?
utils.formatTime(model.last_event_date, false) :
// e.g. "5 Dec"
model.last_event_date.getFullYear() ===
new Date().getFullYear() ?
Qt.formatDate(model.last_event_date, "d MMM") :
// e.g. "Jan 2020"
Qt.formatDate(model.last_event_date, "MMM yyyy")
}
text: utils.smartFormatDate(model.last_event_date)
}
}

View File

@ -299,6 +299,25 @@ QtObject {
}
function smartFormatDate(date) {
return (
date < new Date(1) ?
"" :
// e.g. "03:24"
dateIsToday(date) ?
formatTime(date, false) :
// e.g. "5 Dec"
date.getFullYear() === new Date().getFullYear() ?
Qt.formatDate(date, "d MMM") :
// e.g. "Jan 2020"
Qt.formatDate(date, "MMM yyyy")
)
}
function formatDuration(milliseconds) {
const totalSeconds = milliseconds / 1000