Move room date formatting logic to utils function
This commit is contained in:
		@@ -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)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user