astronomy-bundle-js
astronomy-bundle-js copied to clipboard
Potential wrong results for moonset
I might just be not understanding how the library is supposed to be used. So, first I will try to summarize what I expect the following code to do:
const toi = createTimeOfInterest.fromDate(new Date('2021-05-30T00:00:00'));
const moon = createMoon(toi);
console.log(`rise:${(await moon.getRise(location)).getDate()}`);
console.log(`set:${(await moon.getSet(location)).getDate()}`);
My expectation is the code prints the date/time for the next moonrise and moonset after May 30th, 12am in local time. Is that right?
What I'm getting, however, is the following:
rise:2021-05-29T22:55:27.000Z
set: 2021-05-29T07:00:44.000Z
The value for moonrise looks good to me. new Date('2021-05-30T00:00:00')
corresponds to 2021-05-29T22:00:00Z
(as I live in Barcelona). So, the first moonrise takes place 55 minutes after that (12:55 am, local time). But, the value for moonset happens before the time of interest I specified. Is this expected?
I assume you used Barcelona. So I used the following coorodinates 41.4°, 2.167°
to reproduce the issue.
When I compare the results with https://www.timeanddate.com/moon/spain/barcelona the calculation looks correct:
rise:Sun May 30 2021 00:55:32 GMT+0200 (GMT+02:00) // 23:55:32 UTC
set:Sat May 29 2021 09:00:43 GMT+0200 (GMT+02:00) // 07:00:43 UTC
Which is confusing is the day which changes in the calculation from 30th to 29th of May. Using the CEST TimeZone (UTC+2) there is only one moonset on 29.05.2021 and a moonrise and moonset on 30.05.2021. Using UTC there is only one moonset on 30.05.2021. Technically this calculation is calculating the transit of the moon for a given day and then iterating the values for set and rise referring to that transit. Which can result into a change of the day. Due to the moon's revolution period of about 27 days it even happens that there is no transit for the specified day.
I agree: If you want to calculate the rise and set of the moon for a given day, you don't expect the result to change the day. It may better to result into an error message: "No transit/rise/set possible".
The date calculations don't roll over properly when they get past midnight. This calculates the moon setting before rising.
const location: Location = {
lat: 49.8175, lon: 15.4730 // Czechia
};
const toi = createTimeOfInterest.fromDate(new Date()); // Sun Nov 06 2022 12:15:27 GMT+0100 (Central European Standard Time)
const fullMoon = createMoon(toi).getUpcomingFullMoon()
const moon = await createMoon(fullMoon);
const toiRise = await moon.getRise(location); // { "time": { "year": 2022, "month": 12, "day": 8, "hour": 14, "min": 47, "sec": 46 }, "jd": 2459922.1165046296, "T": 0.2293529501609749 }
const toiTransit = await moon.getTransit(location); // { "time": { "year": 2022, "month": 12, "day": 8, "hour": 23, "min": 28, "sec": 33 }, "jd": 2459922.4781597224, "T": 0.2293628517377798 }
const toiSet = await moon.getSet(location); // { "time": { "year": 2022, "month": 12, "day": 8, "hour": 7, "min": 13, "sec": 19 }, "jd": 2459921.800914352, "T": 0.2293443097700706 }
The day starts at 00:00 and ends and 23:59:59. The moonset for Nov 08 2022 is at 07:13.
So if you want to moon set for after midnight, you need to add +1 day.
@betabandido do you still think this is a bug? Otherwise I would close this issue.