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

getUpcomingLastQuarter skipping actual next date of last quarter moon phase #21

Open
swgordon opened this issue Jan 7, 2021 · 5 comments

Comments

@swgordon
Copy link

swgordon commented Jan 7, 2021

If I run this

const startDate: Date = new Date(Date.UTC(2021, 1, 1));
const toi = createTimeOfInterest.fromDate(startDate);
const lastQuarterDate = createMoon(toi).getUpcomingLastQuarter();

Assuming I am not missing something, lastQuarterDate should be on the 4th of Feb 2021.
Instead, what I am getting is the 6th of March 2021, which is the date of the last quarter moon phase after the upcoming last quarter.
(library version is 5.17.8)

@hjy1210
Copy link
Contributor

hjy1210 commented Jan 8, 2021

quote from MDN docs : Date

monthIndex
Integer value representing the month, beginning with 0 for January to 11 for December.

So
new Date(Date.UTC(2021, 1, 1)) cooresponding to Feb. 1, 2021
new Date(Date.UTC(2021, 0, 1)) cooresponding to Jan. 1, 2021

@andrmoel
Copy link
Owner

andrmoel commented Jan 13, 2021

@hjy1210 thank. That is correct.
I do not recommend to use the Date object. Better use

createTimeOfInterest.fromTime(2021, 1, 1);

@swgordon
Copy link
Author

  1. @hjy1210 just to be clear.
    I am providing Date.UTC(2021, 1, 1) expecting to get moon phase for FEB
    Instead I am getting moon phase for MARCH

I am not expecting to get moon phase for Jan, which absolutely would mean I had screwed up the month.

  1. Also to be clear, new moon/full moon/first quarter work as expected.
    In hindsight should have said this initially.
    For example,
const startDate: Date = new Date(Date.UTC(2021, 2, 1));
const toi = createTimeOfInterest.fromDate(startDate);

const fullMoon = createMoon(toi).getUpcomingFullMoon(); // (RIGHT) yields  Sun Mar 28 2021 18:49:11 GMT+0000 (GMT)
const newMoon = createMoon(toi).getUpcomingNewMoon(); // (RIGHT) yields Sat Mar 13 2021 10:22:44 GMT+0000 (GMT)
const lastQuarterMoon = createMoon(toi).getUpcomingLastQuarter(); // (*WRONG*) yields   Sun Apr 04 2021 10:03:50 GMT+0000 (GMT)
const firstQuarterMoon = createMoon(toi).getUpcomingFirstQuarter(); // (RIGHT) yields  Sun Mar 21 2021 14:41:52 GMT+0000 (GMT)


@hjy1210
Copy link
Contributor

hjy1210 commented Jan 14, 2021

@swgordon

Now I understand what you mean. Sorry for mis-understanding.

I modify your snippet as follows:

function test(year,month,date,hours=0,minutes=0,seconds=0) {
    const toi = createTimeOfInterest.fromTime(year,month,date,hours,minutes,seconds);
    console.log("start date:",toi.getDate())
    
    console.log("getUpcomingFullMoon: ", createMoon(toi).getUpcomingFullMoon().getDate()) 
    console.log("getUpcomingNewMoon: ", createMoon(toi).getUpcomingNewMoon().getDate()); 
    console.log("getUpcomingLastQuarter: ", createMoon(toi).getUpcomingLastQuarter().getDate());
    console.log("getUpcomingFirstQuarter: ", createMoon(toi).getUpcomingFirstQuarter().getDate());
}
test(2021,3,14)

Then I got result:

start date: 2021-03-14T00:00:00.000Z
getUpcomingFullMoon:  2021-03-28T18:49:11.000Z
getUpcomingNewMoon:  2021-03-13T10:22:44.000Z
getUpcomingLastQuarter:  2021-04-04T10:03:50.000Z
getUpcomingFirstQuarter:  2021-03-21T14:41:52.000Z

Note: "getUpcomingNewMoon: 2021-03-13T10:22:44.000Z" is BEFORE "start date: 2021-03-14T00:00:00.000Z"

This issue thread is closed by the author, so I suggest you raise new issue about this fact.

@andrmoel andrmoel reopened this Jan 14, 2021
@hjy1210
Copy link
Contributor

hjy1210 commented Jan 14, 2021

@andrmoel

I got data from https://tidesandcurrents.noaa.gov/moon_phases.shtml?year=2021&data_type=monMar and
https://tidesandcurrents.noaa.gov/moon_phases.shtml?year=2021&data_type=monApr

NewMoon      Mar    	13    	10:21
FirstQuarter Mar    	21    	14:40
FullMoon     Mar    	28    	18:48
LastQuatrer  Apr    	04    	10:02

Compare with result got from astronomy-bundle

start date: 2021-03-14T00:00:00.000Z
getUpcomingNewMoon:  2021-03-13T10:22:44.000Z
getUpcomingFirstQuarter:  2021-03-21T14:41:52.000Z
getUpcomingFullMoon:  2021-03-28T18:49:11.000Z
getUpcomingLastQuarter:  2021-04-04T10:03:50.000Z

There is more than one minute of difference for every event.

Following are my suggestions:

  1. The computation is based on TD/JDE not UT/JD, maybe we should output time in UT, note deltaT = DT-UT is more than 60 seconds in year 2021.
    (Meeus 2009, page 353 example 49.a do make adjustment for deltaT)
  2. In function getTimeOfInterestOfUpcomingPhase(decimalYear, moonPhase), about the statement
var k = math_1.round((decimalYear - 2000) * 12.3685) + moonPhase;
 formula k in Meeus is just an approximation, so may be we should try from a little early and check the computed JDE of event with JDE of started date to determine is it IS the required.

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

3 participants