MeeusJs icon indicating copy to clipboard operation
MeeusJs copied to clipboard

Wrong sun times in New York

Open PendalF89 opened this issue 8 months ago • 0 comments

In September 2025 there are some wrong dates in New York (see screenshot).

Image

How to reproduce:

function normalizeTime(sec) {
    return ((sec % 86400) + 86400) % 86400;
}

function suncalcMeeus(myDateJS, lat, lon, height) {
// gets sun position and times in UTC
    var jdo = new A.JulianDay(myDateJS);
    var coord = A.EclCoord.fromWgs84(lat, lon, height);

    // gets the position of the sun
    var tp = A.Solar.topocentricPosition(jdo, coord, true);
    var altRad = tp.hz.alt;
    var altDeg = altRad * 180 / Math.PI;
    var azRad = tp.hz.az;
    var azDeg = azRad * 180 / Math.PI;
    var distKm =  tp.delta; // debug

    azRad = azRad  +  Math.PI ;
    azDeg = azDeg + 180;


    // gets the rise, transit and set time of the sun
    var times = A.Solar.times(jdo, coord);


    return {
        sunAzimuthRad : azRad,
        sunAltitudeRad : altRad,
        sunAzimuthDegrees : azDeg,
        sunAltitudeDegrees : altDeg,
        sunDistance : distKm,
        rise : A.Coord.secondsToHMSStr(normalizeTime(times.rise -14400)), // 14400 is TZ shift in seconds
        riseJS : new Date(myDateJS.getUTCFullYear() + "-" + (myDateJS.getUTCMonth()+1) + "-" + myDateJS.getUTCDate() + " "  + A.Coord.secondsToHMSStr(times.rise) + "Z"),
        transit : A.Coord.secondsToHMSStr(normalizeTime(times.transit -14400)),
        transitJS : new Date(myDateJS.getUTCFullYear() + "-" + (myDateJS.getUTCMonth()+1) + "-" + myDateJS.getUTCDate() + " "  + A.Coord.secondsToHMSStr(times.transit) + "Z"),
        set: A.Coord.secondsToHMSStr(normalizeTime(times.set -14400)),
        setJS : new Date(myDateJS.getUTCFullYear() + "-" + (myDateJS.getUTCMonth()+1) + "-" + myDateJS.getUTCDate() + " "  + A.Coord.secondsToHMSStr(times.set) + "Z"),
    }
}


const dates = [
    new Date(Date.UTC(2025, 8, 19)),
    new Date(Date.UTC(2025, 8, 20)),
    new Date(Date.UTC(2025, 8, 21)),
    new Date(Date.UTC(2025, 8, 22)),
    new Date(Date.UTC(2025, 8, 23)),
    new Date(Date.UTC(2025, 8, 24)),
    new Date(Date.UTC(2025, 8, 25))
];

const results = dates.map(date => {
    const times = suncalcMeeus(date, 40.7142700, -74.0059700);
    return {
        date: date.toISOString().slice(0, 10),
        rise: times.rise,
        transit: times.transit,
        set: times.set
    };
});

console.table(results);

PendalF89 avatar Feb 14 '25 07:02 PendalF89