MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

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

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    4 Posts 2 Posters 579 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      todsandberg
      last edited by

      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!

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @todsandberg
        last edited by

        @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;
        }
        

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • T Offline
          todsandberg
          last edited by

          @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.

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @todsandberg
            last edited by

            @todsandberg does it make any diffference?

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post
            Enjoying MagicMirror? Please consider a donation!
            MagicMirror created by Michael Teeuw.
            Forum managed by Sam, technical setup by Karsten.
            This forum is using NodeBB as its core | Contributors
            Contact | Privacy Policy