haraldh / SunCalc

Garmin Connect IQ Widget to calculate Dusk, Dawn, Sunset, Sunrise, Blue Hour, etc.
https://apps.garmin.com/en-US/apps/87b86650-a443-43ea-9dcb-29e4051a5722
GNU Lesser General Public License v2.1
34 stars 3 forks source link

fromJulian() should call toNumber() #6

Open evilwombat opened 8 months ago

evilwombat commented 8 months ago

Long story short, I'm ending up with Moments backed by a floating point type (rather than an int type) when running on sim. This leads to truly bizarre results, arising from what I believe is epoch times being stored in single-precision floats, then experiencing loss of precision due to the magnitude of the values involved.

See https://forums.garmin.com/developer/connect-iq/f/discussion/354859/monkey-business-in-data-types-used-by-moment-internals.

Seeing this issue on sim only, while Moments on real HW seem to cast-to-int in their constructor.

Workaround:

function fromJulian(j) {
    return new Time.Moment(((j + 0.5 - J1970) * DAYS).toNumber());
}