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

Calendar Module: 46 minutes = "in 1 hour": How to change the way relative time is shown?



  • Appointment starts in X minutes [how can we adjust what is shown? and when it switches from hours to minutes]

    I would like to change magic mirror settings to show relative time is displayed in the calendar module.
    I have spent 1-2 hours trying things to solve this, seemingly simple, challenge, without a solution yet. Are you able to solve it?

    Example:

    • Current time is 11:43
    • Appointment at 12:30

    Current state:

    • Appointment starts in 1 hour (even though it is LESS than 1 hour)

    .
    Desired behavior:

    • Appointment starts in 47 minutes

    It seems like this moment setting holds the key, but I haven’t been able to get it to work. (or find the right file location (or setting)to change)
    moment.relativeTimeThreshold(‘s’, 40);

    “Bonus points” for a solution that shows relative time to work with minutes >60… (example: 90 minutes left or 1h 30m left)

    Any help is greatly appreciated!



  • @todsandberg well, its here in calendar.js. line 329-331

     							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());
    

    fixed up i think

    							if (event.startDate - now < this.config.getRelative * oneHour) {
    								// If event is within 6 hour, display 'in xxx' time format or moment.fromNow()
                                                                    var m = moment(event.startDate, "x")
                                                                    if(this.config.timeThreshold!=undefined){
                                                                        m.relativeTimeThreshold( 
                                                                             this.config.timeThreshold.unit,
                                                                             this.config.timeThreshold.limit);
                                                                    }
    								timeWrapper.innerHTML = this.capFirst(m.fromNow());
    

    with the config item

    timeThreshold: {unit:minutes,limit:55},
    

    altho to get the right formatting, it might take overriding the fromNow method
    like this (for example, from https://stackoverflow.com/questions/41508796/moment-js-how-to-use-fromnow-to-return-everything-in-hours)

    moment.fn.fromNow = function (a) {
        var duration = moment().diff(this, 'hours');
        return duration;
    }
    


  • @sdetweil said in Calendar Module: 46 minutes = “in 1 hour”: How to change the way relative time is shown?:

    timeThreshold: {unit:minutes,limit:55},

    Thank you, I have tried your code and will keep trying to get it to work.



  • @todsandberg does it make any diffference?


Log in to reply