mourner / suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
BSD 2-Clause "Simplified" License
3.06k stars 410 forks source link

SunCalc.getMoonTimes returns undefined when today's moon rise was yesterday #163

Open leonidhtc opened 1 year ago

leonidhtc commented 1 year ago

https://github.com/mourner/suncalc/blob/6bc2757074c1e5eaa2389aa2ab36806f04c6d2a0/suncalc.js#L303 Today Thu Nov 17 2022 21:23:39 GMT+0300 (Moscow Standard Time) in Moscow lat = 55.8215625, lng = 37.3774375 the function SunCalc.getMoonTimes returns undefined because rise = undefined. Today's moon rise was yesterday. See the screenshot. rise-undefined

Phoscur commented 2 months ago

Types also miss to reflect this, either rise or set attributes may be missing if it happens on another day:

export interface GetMoonTimes {
    rise: Date; // actually optional
    set: Date; // actually optional
    alwaysUp?: true;
    alwaysDown?: true;
}

Example:

10.7.2024 12:00 Berlin/Europe { rise: 2024-07-10T08:11:47.515Z }

But the next day, I find the alignment I'm looking for?:

11.7.2024 12:00 Berlin/Europe { rise: 2024-07-11T09:19:42.301Z, set: 2024-07-10T22:01:34.456Z }

Sunset: 11.7.2024, 21:30:20 Moonset: 11.7.2024, 00:01:34

I should get the moonset in the first query for the 10th, why not?