From 70558d902c6d7b13cdb1ee6adaed777dbf8d7592 Mon Sep 17 00:00:00 2001 From: claire Date: Fri, 24 Mar 2023 12:55:41 -0700 Subject: [PATCH] fixed details of lunar phase calculation --- Home.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Home.md b/Home.md index ef391f6..7ddabf6 100644 --- a/Home.md +++ b/Home.md @@ -317,11 +317,12 @@ I can't take credit for figuring out the math on this. I was lucky to find [this Here's the overview: 1. Use the lunar cycle constant `29.53058770576` (`LunarDays`), and calculate its duration in seconds as `lunarSecs`. -2. Calculate the time (in seconds) between the user date and `lunarSecs` as `totalSecs`. -3. If the result is positive, it's valid, so calculate the modulus (remainder) of `totalSecs` divided by `lunarSecs`, which will return the total seconds that have passed in the current cycle as `currSecs`. -4. Divide `currSecs` by `lunarSecs` to find the current position in the lunar cycle as `currentFrac`. -5. Multiply `currFrac` by `lunarDays` to get this value in days as `currDays`. -6. Find the correct moon phase based on the value of `currDays`. +2. Convert date of first full moon in 2000 (January 6 at 18:14 UTC) to unix timestamp as `baseDate`. +3. Calculate the time (in seconds) between the user date and `baseDate` as `totalSecs`. +4. If the result is positive, it's valid, so calculate the modulus (remainder) of `totalSecs` divided by `lunarSecs`, which will return the total seconds that have passed in the current cycle as `currSecs`. +5. Divide `currSecs` by `lunarSecs` to find the current position in the lunar cycle as `currentFrac`. +6. Multiply `currFrac` by `lunarDays` to get this value in days as `currDays`. +7. Find the correct moon phase based on the value of `currDays`. This is all just basic arithmetic, so let's get into the Swift implementation.