mourner / suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
BSD 2-Clause "Simplified" License
3.07k stars 412 forks source link

The values do not seem to be correct in different longitude #121

Open ghost opened 6 years ago

ghost commented 6 years ago

I tested it through the following codes:

const suncalc=require('suncalc');

console.log(suncalc.getTimes(new Date(1971, 10, 27), 25.0, 119.0).sunrise); console.log(suncalc.getTimes(new Date(1971, 10, 27), 25.0, 120.0).sunrise); console.log(suncalc.getTimes(new Date(1971, 10, 27), 25.0, 121.0).sunrise); console.log(suncalc.getTimes(new Date(1971, 10, 27), 25.0, 122.0).sunrise);

The results are:

1971-11-25T22:29:44.251Z 1971-11-25T22:25:44.130Z 1971-11-26T22:22:27.438Z 1971-11-26T22:18:27.318Z

I think the date shouldn't be 11-25.

aoizoijoizj commented 6 years ago

Maybe the problem is in time zones. Test this: console.log(suncalc.getTimes(new Date(Date.UTC(1971, 10, 27)), 25.0, 119.0).sunrise); console.log(suncalc.getTimes(new Date(Date.UTC(1971, 10, 27)), 25.0, 120.0).sunrise); console.log(suncalc.getTimes(new Date(Date.UTC(1971, 10, 27)), 25.0, 121.0).sunrise); console.log(suncalc.getTimes(new Date(Date.UTC(1971, 10, 27)), 25.0, 122.0).sunrise);