UNPKG

@observerly/astrometry

Version:

observerly's lightweight, zero-dependency, type safe astrometry library written in Typescript for calculating the position of celestial objects in the sky.

60 lines (59 loc) 2.58 kB
import { convertEquatorialToHorizontal as w } from "./coordinates.js"; import { g as C } from "./epoch-nmyjNjKp.js"; import { getCorrectionToHorizontalForRefraction as m } from "./refraction.js"; import { getSolarEquatorialCoordinate as J } from "./sun.js"; import { c as e, e as H } from "./utilities-BM-rBPno.js"; const R = (n, o) => { const { latitude: a, longitude: c } = o, l = C(n), r = Math.ceil(l - (2451545 + 9e-4) + 69.184 / 86400) - c / 360, t = (357.5291 + 0.98560028 * r) % 360, M = 1.9148 * Math.sin(e(t)) + 0.02 * Math.sin(e(2 * t)) + 3e-4 * Math.sin(e(3 * t)), h = (t + M + 180 + 102.9372) % 360, s = 2451545 + r + 53e-4 * Math.sin(e(t)) - 69e-4 * Math.sin(e(2 * h)), i = H(Math.asin(Math.sin(e(h)) * Math.sin(e(23.45)))), g = H(Math.acos(Math.sin(e(-0.833) - Math.sin(e(a)) * Math.sin(e(i))) / Math.cos(e(a)) * Math.cos(e(i)))), f = s - g / 360, D = s + g / 360; return { sunrise: new Date((f - 24405875e-1) * 86400 * 1e3), noon: new Date((s - 24405875e-1) * 86400 * 1e3), sunset: new Date((D - 24405875e-1) * 86400 * 1e3), J: r, ha: g }; }, T = (n, o, a = -12, c = 288.15, l = 101325) => { n = new Date(new Date(n.setHours(0, 0, 0, 0)).getTime()); const { sunrise: u, noon: r, sunset: t } = R(n, o); if (u === null || t === null) return { sunrise: null, noon: null, sunset: null }; let M = null; for (let s = -120; s <= 120; s++) { const i = new Date(u.getTime() + 6e4 * s), { ra: g, dec: f } = J(i), D = w(i, o, { ra: g, dec: f }); if (m(D, c, l).alt > a && M === null) { M = i; break; } } let h = null; for (let s = -120; s <= 120; s++) { const i = new Date(t.getTime() + 6e4 * s), { ra: g, dec: f } = J(i), D = w(i, o, { ra: g, dec: f }); if (m(D, c, l).alt < a && h === null) { h = i; break; } } return { sunrise: M || u, noon: r, sunset: h || t }; }, F = (n, o, a = -12, c = 288.15, l = 101325) => { const { sunset: u } = T(n, o, a, c, l), { sunrise: r } = T(new Date(n.getTime() + 6e4 * 60 * 24), o, a, c, l); return { start: u, end: r }; }, N = (n, o, a = -12, c = 288.15, l = 101325) => { const u = new Date(n.getFullYear(), n.getMonth(), n.getDate(), n.getHours(), n.getMinutes(), n.getSeconds(), n.getMilliseconds()), { sunrise: r, sunset: t } = T(n, o, a, c, l); return r === null || t === null ? !1 : u.getTime() <= r.getTime() || u.getTime() >= t.getTime(); }; export { R as getGeneralizedSolarTransit, F as getNight, T as getSolarTransit, N as isNight }; //# sourceMappingURL=night.js.map