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.

    MMM-MealViewer

    Scheduled Pinned Locked Moved Utilities
    10 Posts 5 Posters 854 Views 4 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.
    • E Offline
      ewingfox
      last edited by

      Hello @dadandel !

      I love this (and more importantly, my WIFE and kiddos love this module - GREAT WORK!

      My wife does meal planning, shopping and tasks me with meal prep for the upcoming week on the weekends, so she really wants to see the next week’s school lunches on Friday evening when she’s in the fridge and going through what we have, and what meals my kiddo wants to eat at school and which meals they want to pack a lunch for.

      Currently, the getDateRange function (which is super robust, excellent work) is strictly ‘look back’. I did quite a bit of testing (thank you for baking in all the testing and logging logic!!!) and my testing shows that you can maintain all of the robustness and add the ‘look ahead’ my wife is looking for by updating the function just a bit like:

      getDateRange: function (startDay, endDay, testMode = false, testDate = null) {
          let today;
      
          if (testMode && testDate) {
              const [year, month, day] = testDate.split('-').map(Number);
              today = new Date(year, month - 1, day);
              console.log(`Using test date (local timezone): ${today.toLocaleString()}`);
          } else {
              today = new Date();
          }
      
          const currentDay = today.getDay();
          console.log(`Current day of week: ${currentDay}`);
      
          // ------------------------------------------------------------
          // Calculate the date for the week's start (most recent startDay)
          // ------------------------------------------------------------
          const startDate = new Date(today);
          const daysToSubtract = ((currentDay - startDay + 7) % 7);
          startDate.setDate(today.getDate() - daysToSubtract);
      
          console.log(`Days to subtract: ${daysToSubtract}`);
          console.log(`Initial start date: ${startDate.toLocaleString()}`);
      
          // ------------------------------------------------------------
          // Calculate the end date (inclusive range)
          // ------------------------------------------------------------
          const endDate = new Date(startDate);
          const daysInRange = (endDay - startDay + 7) % 7 + 1;
          endDate.setDate(startDate.getDate() + daysInRange - 1);
      
          // ------------------------------------------------------------
          // LOOK-AHEAD LOGIC
          // If today is on or after the trigger day (Friday for Mon–Fri),
          // shift the entire range forward by one week
          // ------------------------------------------------------------
          const lookAheadTriggerDay = (startDay + 4) % 7;
      
          if (currentDay >= lookAheadTriggerDay) {
              console.log("Look-ahead condition met — shifting range to next week");
              startDate.setDate(startDate.getDate() + 7);
              endDate.setDate(endDate.getDate() + 7);
          }
      
          console.log(`Final start date: ${startDate.toLocaleString()}`);
          console.log(`Final end date: ${endDate.toLocaleString()}`);
      
          // ------------------------------------------------------------
          // Format output
          // ------------------------------------------------------------
          const formatDate = (date) => {
              const year = date.getFullYear();
              const month = String(date.getMonth() + 1).padStart(2, '0');
              const day = String(date.getDate()).padStart(2, '0');
              return `${month}-${day}-${year}`;
          };
      
          return {
              start: formatDate(startDate),
              end: formatDate(endDate)
          };
      },
      

      90efbaf8-4cdc-4f3a-8df4-719742cba468-image.png

      S E 2 Replies Last reply Reply Quote 1
      • S Offline
        sdetweil @ewingfox
        last edited by

        @ewingfox in this open source world the way to approach this is to submit your update as a pull request to the original module

        Then the author doesn’t have to spend time inventing the changes, only reviewing your work

        So, on GitHub
        Fork the module, now you have a linked copy
        git clone your copy, same as you did the original (only one in a place at a time)
        Update your copy
        git add your changes
        git commit your changes to your local copy of the repo
        git push. To upload your copy to GitHub, updating your fork
        Use GitHub to submit/contribute your changes to the original module,

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        E 1 Reply Last reply Reply Quote 2
        • E Offline
          ewingfox @sdetweil
          last edited by

          @sdetweil as usual - you are very correct lol - this was sheer laziness on my part!

          <instinctively ducks to see if my DevOps lead is hurling a pot in my direction, remembers that she’s 7,600 miles away, ducks again anyway>

          1 Reply Last reply Reply Quote 0
          • E Offline
            ewingfox @ewingfox
            last edited by

            @sdetweil - At work, all of my criteria and commentary lives in jira and my PR’s are pretty lean [read: RTSIDXCMT-11142, accept my d**n PR if you want that bug fix] .

            I’d appreciate any feedback on manners/standards for submitting PR to open source projects so I can better align with norms!

            https://github.com/ElliAndDad/MMM-MealViewer/pull/4

            Thank you for being such an active mod/admin/mentor!

            Take care,

            E

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

              @ewingfox one of the banes of open source is every author has their own style. So a PR here is different than a PR there.

              Sam

              How to add modules

              learning how to use browser developers window for css changes

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