-
-
Save datatypevoid/f4dd1f6439feaa588bb2aaf4f8f4361f to your computer and use it in GitHub Desktop.
| export { EMoonPhase, EMoonPhaseName, MOON_PHASE_NAMES, moonPhase } | |
| const { round, trunc: truncate } = Math | |
| enum EMoonPhase { | |
| New = 0, | |
| WaxingCrescent, | |
| QuarterMoon, | |
| WaxingGibbous, | |
| Full, | |
| WaningGibbous, | |
| LastQuarter, | |
| WaningCrescent, | |
| COUNT = 8 | |
| } | |
| enum EMoonPhaseName { | |
| New = 'New', | |
| WaxingCrescent = 'Waxing Crescent', | |
| QuarterMoon = 'Quarter Moon', | |
| WaxingGibbous = 'Waxing Gibbous', | |
| Full = 'Full', | |
| WaningGibbous = 'Waning Gibbous', | |
| LastQuarter = 'Last Quarter', | |
| WaningCrescent = 'Waning Crescent', | |
| COUNT = 'COUNT' | |
| } | |
| const MOON_PHASE_NAMES: EMoonPhaseName[] = [ // Look-up table. | |
| EMoonPhaseName.New, | |
| EMoonPhaseName.WaxingCrescent, | |
| EMoonPhaseName.QuarterMoon, | |
| EMoonPhaseName.WaxingGibbous, | |
| EMoonPhaseName.Full, | |
| EMoonPhaseName.WaningGibbous, | |
| EMoonPhaseName.LastQuarter, | |
| EMoonPhaseName.WaningCrescent, | |
| EMoonPhaseName.COUNT | |
| ] | |
| // Reference: http://individual.utoronto.ca/kalendis/lunar/#FALC | |
| // Also known as a synodic month. | |
| // An average synodic month takes 29 days, 12 hours, 44 minutes, 3 seconds. | |
| const LUNAR_CYCLE = 29.53058770576 | |
| const DAYS_PER_YEAR = 365.25 | |
| const DAYS_PER_MONTH = 30.6 | |
| // Number of days since known new moon on `1900-01-01`. | |
| const DAYS_SINCE_NEW_MOON_1900_01_01 = 694039.09 | |
| interface IResult { name: EMoonPhaseName, phase: EMoonPhase } | |
| // Ported from `http://www.voidware.com/moon_phase.htm`. | |
| function moonPhase (date: Date = new Date()): IResult { | |
| // let year = date.getYear() | |
| let year: number = date.getFullYear() | |
| let month: number = date.getMonth() | |
| const day: number = date.getDay() | |
| if (month < 3) { | |
| year-- | |
| month += 12 | |
| } | |
| month++ | |
| let totalDaysElapsed: number = DAYS_PER_YEAR | |
| * year | |
| + DAYS_PER_MONTH | |
| * month | |
| + day | |
| - DAYS_SINCE_NEW_MOON_1900_01_01 | |
| totalDaysElapsed /= LUNAR_CYCLE // Divide by the lunar cycle. | |
| let phase: number = truncate(totalDaysElapsed) | |
| /* | |
| Subtract integer part to leave fractional part of original | |
| `totalDaysElapsed`. | |
| */ | |
| totalDaysElapsed -= phase | |
| // Scale fraction from `0-8`. | |
| phase = round(totalDaysElapsed * 8) | |
| phase = phase & 7 // `0` and `8` are the same so turn `8` into `0`. | |
| if (phase >= EMoonPhase.COUNT || phase < EMoonPhase.New) | |
| throw new Error(`Invalid moon phase: ${phase}`) | |
| return { phase, name: MOON_PHASE_NAMES[phase] } | |
| } |
GitHub doesn't allow users to share emails. What's up?
i think her can not connect. i tried to inter to your website but dont work?
can you develop , calculate moon manzel?
Yes, I think that wouldn't be too hard to add with some investigation into calculating lunar degrees.
how can have contact with you?
sent you a repo collab
Yes, I think that wouldn't be too hard to add with some investigation into calculating lunar degrees.
how contact with you
You're cluttering up the gist man. I sent you a repo collaboration invite so you can contact me through the codebase.
You're cluttering up the gist man. I sent you a repo collaboration invite so you can contact me through the codebase.
i didnt have and received any thing
i accept it.now what?
This is my last message here. Check the README. My email is there.
GitHub doesn't allow users to share emails. What's up?