Skip to content

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

@rudolfolah

Description

@rudolfolah

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions