You are reading a single comment by @HilmarSt and its replies. Click here to read the full conversation.
  • Good morning!

    I just compared the moon phase calculation of the moon phase widget with that of my moon phase complication for analog clocks using the following code:

      function compareMoonphasesAt (today) {
      /**** Code from Moonphase Widget ****/
      
        const MC = 29.5305882, NM = 694039.09;
        var r = 11, mx = this.x + 12; my = this.y + 12;
      
        function moonPhase(d) {
          var tmp, month = d.getMonth(), year = d.getFullYear(), day = d.getDate();
          if (month < 3) {year--; month += 12;}
          tmp = ((365.25 * year + 30.6 * ++month + day - NM) / MC);
          return Math.round(((tmp - (tmp | 0)) * 7)+1);
        }
      
      /**** Code from Moonphase Complication ****/
      
        const MillisPerDay   = 86400000;
        const synodicalMonth = 29.530588;
      
        let Phase = (
          (today/MillisPerDay - new Date(2009,11,31, 20,12,36)/MillisPerDay) % synodicalMonth
        ) / synodicalMonth;
      
        if (Phase < 0) { Phase += 1; } // just in case that date is completely wrong
      
      /**** make the latter comparable to the former ****/
      
        Phase -= 0.5; if (Phase < 0) { Phase += 1; }
        Phase = Math.round(Phase * 7)+1;
      
      /**** print comparison ****/
      
        let day = today.getDate();
        print(
          '2022-01-' + (day < 10 ? '0' : '') + day + ': ' + 
          moonPhase(today) + ' vs. ' + Phase
        );
      }
    
      for (let Day = 17-14; Day < 17+14; Day++) {
        compareMoonphasesAt(new Date(2022,0,Day));
      }
    

    The output of that little script is:

    2022-01-03: 8 vs. 8
    2022-01-04: 1 vs. 1
    2022-01-05: 1 vs. 1
    2022-01-06: 2 vs. 2
    2022-01-07: 2 vs. 2
    2022-01-08: 2 vs. 2
    2022-01-09: 2 vs. 2
    2022-01-10: 3 vs. 3
    2022-01-11: 3 vs. 3
    2022-01-12: 3 vs. 3
    2022-01-13: 3 vs. 3
    2022-01-14: 4 vs. 4
    2022-01-15: 4 vs. 4
    2022-01-16: 4 vs. 4
    2022-01-17: 4 vs. 4
    2022-01-18: 5 vs. 5
    2022-01-19: 5 vs. 5
    2022-01-20: 5 vs. 5
    2022-01-21: 5 vs. 5
    2022-01-22: 5 vs. 5
    2022-01-23: 6 vs. 6
    2022-01-24: 6 vs. 6
    2022-01-25: 6 vs. 6
    2022-01-26: 6 vs. 6
    2022-01-27: 7 vs. 7
    2022-01-28: 7 vs. 7
    2022-01-29: 7 vs. 7
    2022-01-30: 7 vs. 7
    

    This looks as if the calculation itself is correct.

    What might lead to less optimal graphics is the low number of different indices - compared to user requirements (e.g., according to the numbers, "full moon" is shown from Jan 14 to Jan 17 incl. - this collides with "it's ever so slightly slightly waning")

    Thus, what may (might?) finish this discussion could be a more detailed drawing of the current moon phase in the widget?

  • Well, since our formulae seem to be comparable, you may just copy all the code from my moon phase complication and adapt it for your radius and color settings - that's it. Everything else would require more work.

About

Avatar for HilmarSt @HilmarSt started