Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: phase_hunt seeks phases in the past, no guarantee that next new moon is in the future #32

Open
rudolfolah opened this issue Mar 10, 2024 · 0 comments

Comments

@rudolfolah
Copy link

While testing across multiple dates, I ran into this issue where the phases were in the previous month, including the next new moon. The bug is that the provided date is outside of the interval ranging from the previous new moon to the next new moon.

It can be replicated by trying the date July 6th, 2024, (2024-07-06):

const lune = require('lune');
const luxon = require('luxon');
const datetime = luxon.DateTime.fromISO("2024-07-06", { zone: "UTC" });
const jsdate = datetime.toJSDate();
lune.phase_hunt(jsdate);

The output is here, you can see the dates are in June 2024 rather than in July 2024:
Screenshot 2024-03-09 at 7 43 10 PM

And when I try the next day over, 2024-07-07, it shows the phases in July 2024:

Screenshot 2024-03-09 at 7 45 01 PM

To work around this issue, in my code I added a conditional to check if the next new moon is before the provided date and if it is, to run the phase hunt 1 day in the future:

// my codebase is using Luxon
if (phases.nextnew_date.getTime() < date.getTime()) {
  const futureDate = DateTime.fromJSDate(date).plus(Duration.fromObject({ days: 1 })).toJSDate();
  phases = lune.phase_hunt(futureDate);
}

// without Luxon
if (phases.nextnew_date.getTime() < date.getTime()) {
  const futureDate = new Date(date.getTime() + (1000 * 60 * 60 * 24));
  phases = lune.phase_hunt(futureDate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant