janrg / MeeusSunMoon

JavaScript module to calculate times for sunrise, solar noon, and sunset, as well as moon phases based on "Astronomical Algorithms" by Jean Meeus
MIT License
31 stars 9 forks source link

Wrong sunrise data for city with longitude > 90E #25

Closed xouillet closed 3 years ago

xouillet commented 3 years ago

Hi,

While testing your lib with city like Noumea or Auckland, I noticed big errors in sunrise calculation (for example, sunrise in Auckland returns 20:03 NZDT insted of 05:56). Sunset is ok thought (20:38 NZDT). After investigating, error appears with location with a longitude > 90 (but it seems ok with longitude < 90 thought).

The thing is, Auckland is tested in your test dataset, but I've found that all the tests made are not pertinent, because of an error in expectCorrectTimeOrNoEventCode function, as eventTime.diff(refEventTime).minutes always returns 0, (eventTime.diff(refEventTime).as("minutes") should be used here (cf. my pull request).

janrg commented 3 years ago

Oh, wow, thanks. Seems like I made a mistake somwhere when I changed the library from moment to luxon and then made another mistake in the test code that hid it. In addition to what you mentioned, solar noon calculations seem to be broken pretty much everywhere (edit: that was just a small error in the test code). Will try to dig into this but of course if you can find the source of the error I would be very grateful.

xouillet commented 3 years ago

I've managed to find a fix for sunrise/dusk/..., it is indeed linked to a luxon library call.

The solar noon are still broken though

janrg commented 3 years ago

Closed and will release to npm later today. Thanks again for spotting this!

janrg commented 3 years ago

Published on npm