diff --git a/src/gui/MainPane/Room.qml b/src/gui/MainPane/Room.qml index 7a02d820..6541da69 100644 --- a/src/gui/MainPane/Room.qml +++ b/src/gui/MainPane/Room.qml @@ -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) } } diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index a6335248..17dd07be 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -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