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.

    Changing moment.js behavior

    Scheduled Pinned Locked Moved Troubleshooting
    12 Posts 5 Posters 9.7k Views 3 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.
    • yo-lessY Offline
      yo-less Module Developer
      last edited by yo-less

      I’ve just realized that both “today” and “tomorrow” are taken over by the MagicMirror translation engine, this would explain why no change to moments.js locale files made any difference :).

      So if anyone is ever thinking about adjusting the calendar phrase for “today” or “tomorrow”, take a look at your MagicMirror/translations/ folder.

      1 Reply Last reply Reply Quote 0
      • yo-lessY Offline
        yo-less Module Developer
        last edited by

        As the calender.js file takes over the days “TODAY” and “TOMORROW” it was actually quite easy to add another definition to take over the “DAYAFTERTOMORROW”.

        I’ve changed the ‘calender.js’ code to look like this:

        ...
        if (event.fullDayEvent) {
        	if (event.today) {
        		timeWrapper.innerHTML = this.translate("TODAY");
        	} else if (event.startDate - now < one_day && event.startDate - now > 0) {
        		timeWrapper.innerHTML = this.translate("TOMORROW");
        	} else if (event.startDate - now < 2*one_day && event.startDate - now > 0) {
        		timeWrapper.innerHTML = this.translate("DAYAFTERTOMORROW");
        	} else {
        ...
        

        And I’ve adjusted /MagicMirror/translations/de.json to look like this

        ...
        	"TOMORROW": "Morgen",
        	"DAYAFTERTOMORROW": "Übermorgen",
        	"RUNNING": "noch",
        ...
        

        Which led to this:
        0_1472593100725_termine.png

        Great, just what I needed… :)

        I’m aware that this will be overwritten by any update I might perform, but I can’t think of any other way to implement this feature.

        1 Reply Last reply Reply Quote 1
        • MichMichM Offline
          MichMich Admin
          last edited by

          Feel free to send a pull request so anyone can benefit from this. :)

          1 Reply Last reply Reply Quote 0
          • yo-lessY Offline
            yo-less Module Developer
            last edited by

            @MichMich Well, I sort of assumed that a change that somehow breaks the calendar for any other language than German would probably not be merged into the develop branch ^^. But I can have it depend on an if-condition and we can take a look at whether it makes sense to include it in the calendar, will submit a pull request and we’ll take it from there.

            1 Reply Last reply Reply Quote 1
            • MichMichM Offline
              MichMich Admin
              last edited by

              The PR was just merged into the develop branch. I’ve added a translation for Dutch as well.

              1 Reply Last reply Reply Quote 1
              • A Offline
                alina12
                last edited by

                The manipulations with dates can be a time-consuming problem in some cases. Moment.js is a powerful JavaScript library intended to handle with dates and time without any other dependencies.
                Briefly, this library allows working conveniently with parsing, validating as well as displaying dates. Besides, it efficiently handles with a necessity to provide your users around the globe with localized time and the right format depending on their location. Moment.js library supports time zone and internalization.
                You should use it in case you need to implement some features related to dates and time. Look at more JS libraries in the Cleveroad blog

                mobile and web development

                1 Reply Last reply Reply Quote 0
                • C Offline
                  chrisgodyn
                  last edited by

                  How do you actually use moment.js
                  my clock is off and i dont know how to change it.
                  then i got moment.js and still dont know

                  1 Reply Last reply Reply Quote 1
                  • 1
                  • 2
                  • 1 / 2
                  • 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