MagicMirror² v2.5.0 is available! For more information about this release, check out this topic.

Calendar showing 12h time format instead of 24h



  • In my calendar module, all entries in the range two days from now are shown with “tomorrow/day after tomorrow at XX:00”, but the time is shown with 12h time format, although in MagicMirror config timeFormat is set to 24.

    I presume the reason is a function in calendar.js: in case the day of the event is < currentdate - 2 the event is derived from moment.calendar()

    if (event.startDate - now < 2 * oneDay) {
    	// This event is within the next 48 hours (2 days)
    	if (event.startDate - now < this.config.getRelative * oneHour) {
    	        // If event is within 6 hour, display 'in xxx' time format or moment.fromNow()
    		timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
    	} else {
    	        // Otherwise just say 'Today/Tomorrow at such-n-such time'
    		timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").calendar());
    	}
    

    0_1541361649708_17412b76-328a-4c7f-bfb9-0fd3ef744245-image.png
    E.g., first entry should be “Morgen um 16:30”

    The moment.calendar() function is used nowhere else in the module.

    I haven’t noticed this behaviour before, so I’m not sure if I have triggered this somehow or if it has been there before.

    Does anyone have a clue what the problem is?



  • Well I have found the problem.
    But it seems to have been resolved with a recent code update

    For those interested:

    getLocaleSpecification: function(timeFormat) {
    		switch (timeFormat) {
    		case 12: {
    			return { longDateFormat: {LT: "h:mm A"} };
    			break;
    		}
    		case 24: {
    			return { longDateFormat: {LT: "HH:mm"} };
    			break;
    		}
    		default: {
    			return { longDateFormat: {LT: moment.localeData().longDateFormat("LT")} };
    			break;
    		}
    		}
    	},
    

    For case 24 The longDateFormat: hh:mm was wrong. It needs to be HH:mm.
    As said, was already changed.
    Thanks @MichMich