You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportfunctioncalculateMoonPhase(currentDate: Date): number{constnewMoonDate=newDate(Date.UTC(2019,0,6,1,28,0));// Reference New Moon dateconstlunarCycleLength=29.53;// Average length of the lunar cycle in daysconstdiffInDays=(currentDate.getTime()-newMoonDate.getTime())/(1000*3600*24);constmoonPhase=(diffInDays%lunarCycleLength)/lunarCycleLength;returnmoonPhase;}exportfunctionestimateNextMoonPhases(currentDate: Date): {nextNewMoon: string,nextFullMoon: string}{constcurrentMoonPhase=calculateMoonPhase(currentDate);constlunarCycleLength=29.53;// Average length of the lunar cycle in daysletdaysUntilNextNewMoon=lunarCycleLength*(1-currentMoonPhase);if(currentMoonPhase>=0&¤tMoonPhase<0.5){daysUntilNextNewMoon=lunarCycleLength*(0.5-currentMoonPhase);}letdaysUntilNextFullMoon=lunarCycleLength*(0.5-currentMoonPhase);if(currentMoonPhase>=0.5){daysUntilNextFullMoon=lunarCycleLength*(1-currentMoonPhase)+(lunarCycleLength/2);}constnextNewMoon=formatMMDDDate(newDate(currentDate.getTime()+daysUntilNextNewMoon*24*3600*1000));constnextFullMoon=formatMMDDDate(newDate(currentDate.getTime()+daysUntilNextFullMoon*24*3600*1000));return{ nextNewMoon, nextFullMoon };}exportfunctiongetMoonPhaseName(moonPhase: number): string{if(moonPhase<0.03||moonPhase>0.97){return"NewMoon";}elseif(moonPhase<0.22){return"WaxingCrescent";}elseif(moonPhase<0.28){return"FirstQuarter";}elseif(moonPhase<0.47){return"WaxingGibbous";}elseif(moonPhase<0.53){return"FullMoon";}elseif(moonPhase<0.72){return"WaningGibbous";}elseif(moonPhase<0.78){return"LastQuarter";}else{return"WaningCrescent";}}exportfunctiongetMoonPhasesForPeriod(currentDate: Date=newDate()): MoonPhase[]{consttodayMoonPhaseNumber=calculateMoonPhase(currentDate);consttodayMoonPhaseName=getMoonPhaseName(todayMoonPhaseNumber);const{ nextNewMoon, nextFullMoon }=estimateNextMoonPhases(currentDate);consttoday: MoonPhase={date: formatMMDDDate(currentDate),moonPhaseIcon: MoonPhaseIcons[todayMoonPhaseName],name: todayMoonPhaseName,};constnextNewMoonPhase: MoonPhase={date: nextNewMoon,moonPhaseIcon: MoonPhaseIcons["NewMoon"],name: "NewMoon",};constnextFullMoonPhase: MoonPhase={date: nextFullMoon,moonPhaseIcon: MoonPhaseIcons["FullMoon"],name: "FullMoon",};// Determine the sequence based on current phaseletphases: MoonPhase[];if(todayMoonPhaseNumber<0.5){// Today -> Next Full Moon -> Next New Moonphases=[today,nextFullMoonPhase,nextNewMoonPhase];}else{// Today -> Next New Moon -> Next Full Moonphases=[today,nextNewMoonPhase,nextFullMoonPhase];}returnphases;}
The text was updated successfully, but these errors were encountered:
Internationalization support was something I had considered based on the lunar phase enumeration, but adds a hefty amount of complexity.
Any i18n implementation and corresponding translations would be local to that project.
Similar requests for next cycles have been made, in #30, and pull request in #17.
My formula has a small margin of error that I never had time to resolve. There are some other aspects in regards to how this library handles time windows versus events.
The text was updated successfully, but these errors were encountered: