• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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 465 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 Apr 6, 2020, 6:31 PM

    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 Apr 6, 2020, 8:05 PM Reply Quote 0
    • S Offline
      sdetweil @todsandberg
      last edited by Apr 6, 2020, 8:05 PM

      @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 Apr 9, 2020, 10:24 PM

        @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 Apr 9, 2020, 10:31 PM Reply Quote 0
        • S Offline
          sdetweil @todsandberg
          last edited by Apr 9, 2020, 10:31 PM

          @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
          • 1 / 1
          1 / 1
          • First post
            2/4
            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