@arcosmos/erfa 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +56 -0
- package/README.md +109 -2
- package/dist/a2af.d.ts +36 -0
- package/dist/a2af.d.ts.map +1 -0
- package/dist/a2af.js +44 -0
- package/dist/a2af.js.map +1 -0
- package/dist/a2tf.d.ts +36 -0
- package/dist/a2tf.d.ts.map +1 -0
- package/dist/a2tf.js +42 -0
- package/dist/a2tf.js.map +1 -0
- package/dist/af2a.d.ts +19 -0
- package/dist/af2a.d.ts.map +1 -0
- package/dist/af2a.js +34 -0
- package/dist/af2a.js.map +1 -0
- package/dist/anp.d.ts +8 -0
- package/dist/anp.d.ts.map +1 -0
- package/dist/anp.js +16 -0
- package/dist/anp.js.map +1 -0
- package/dist/anpm.d.ts +8 -0
- package/dist/anpm.d.ts.map +1 -0
- package/dist/anpm.js +16 -0
- package/dist/anpm.js.map +1 -0
- package/dist/bi00.d.ts +27 -0
- package/dist/bi00.d.ts.map +1 -0
- package/dist/bi00.js +40 -0
- package/dist/bi00.js.map +1 -0
- package/dist/bp06.d.ts +27 -0
- package/dist/bp06.d.ts.map +1 -0
- package/dist/bp06.js +46 -0
- package/dist/bp06.js.map +1 -0
- package/dist/c2s.d.ts +14 -0
- package/dist/c2s.d.ts.map +1 -0
- package/dist/c2s.js +21 -0
- package/dist/c2s.js.map +1 -0
- package/dist/cal2jd.d.ts +27 -0
- package/dist/cal2jd.d.ts.map +1 -0
- package/dist/cal2jd.js +58 -0
- package/dist/cal2jd.js.map +1 -0
- package/dist/constants.d.ts +59 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +60 -0
- package/dist/constants.js.map +1 -0
- package/dist/cp.d.ts +9 -0
- package/dist/cp.d.ts.map +1 -0
- package/dist/cp.js +10 -0
- package/dist/cp.js.map +1 -0
- package/dist/cpv.d.ts +9 -0
- package/dist/cpv.d.ts.map +1 -0
- package/dist/cpv.js +12 -0
- package/dist/cpv.js.map +1 -0
- package/dist/cr.d.ts +9 -0
- package/dist/cr.d.ts.map +1 -0
- package/dist/cr.js +12 -0
- package/dist/cr.js.map +1 -0
- package/dist/d2dtf.d.ts +49 -0
- package/dist/d2dtf.d.ts.map +1 -0
- package/dist/d2dtf.js +142 -0
- package/dist/d2dtf.js.map +1 -0
- package/dist/d2tf.d.ts +36 -0
- package/dist/d2tf.d.ts.map +1 -0
- package/dist/d2tf.js +77 -0
- package/dist/d2tf.js.map +1 -0
- package/dist/dat.d.ts +55 -0
- package/dist/dat.d.ts.map +1 -0
- package/dist/dat.js +168 -0
- package/dist/dat.js.map +1 -0
- package/dist/datini.d.ts +26 -0
- package/dist/datini.d.ts.map +1 -0
- package/dist/datini.js +37 -0
- package/dist/datini.js.map +1 -0
- package/dist/dtdb.d.ts +105 -0
- package/dist/dtdb.d.ts.map +1 -0
- package/dist/dtdb.js +1076 -0
- package/dist/dtdb.js.map +1 -0
- package/dist/dtf2d.d.ts +45 -0
- package/dist/dtf2d.d.ts.map +1 -0
- package/dist/dtf2d.js +112 -0
- package/dist/dtf2d.js.map +1 -0
- package/dist/eceq06.d.ts +24 -0
- package/dist/eceq06.d.ts.map +1 -0
- package/dist/eceq06.js +44 -0
- package/dist/eceq06.js.map +1 -0
- package/dist/ecm06.d.ts +30 -0
- package/dist/ecm06.d.ts.map +1 -0
- package/dist/ecm06.js +45 -0
- package/dist/ecm06.js.map +1 -0
- package/dist/epb.d.ts +24 -0
- package/dist/epb.d.ts.map +1 -0
- package/dist/epb.js +30 -0
- package/dist/epb.js.map +1 -0
- package/dist/epb2jd.d.ts +14 -0
- package/dist/epb2jd.d.ts.map +1 -0
- package/dist/epb2jd.js +20 -0
- package/dist/epb2jd.js.map +1 -0
- package/dist/epj.d.ts +24 -0
- package/dist/epj.d.ts.map +1 -0
- package/dist/epj.js +29 -0
- package/dist/epj.js.map +1 -0
- package/dist/epj2jd.d.ts +14 -0
- package/dist/epj2jd.d.ts.map +1 -0
- package/dist/epj2jd.js +20 -0
- package/dist/epj2jd.js.map +1 -0
- package/dist/eqec06.d.ts +24 -0
- package/dist/eqec06.d.ts.map +1 -0
- package/dist/eqec06.js +44 -0
- package/dist/eqec06.js.map +1 -0
- package/dist/era00.d.ts +29 -0
- package/dist/era00.d.ts.map +1 -0
- package/dist/era00.js +51 -0
- package/dist/era00.js.map +1 -0
- package/dist/fw2m.d.ts +51 -0
- package/dist/fw2m.d.ts.map +1 -0
- package/dist/fw2m.js +61 -0
- package/dist/fw2m.js.map +1 -0
- package/dist/g2icrs.d.ts +33 -0
- package/dist/g2icrs.d.ts.map +1 -0
- package/dist/g2icrs.js +69 -0
- package/dist/g2icrs.js.map +1 -0
- package/dist/gmst06.d.ts +32 -0
- package/dist/gmst06.d.ts.map +1 -0
- package/dist/gmst06.js +49 -0
- package/dist/gmst06.js.map +1 -0
- package/dist/icrs2g.d.ts +33 -0
- package/dist/icrs2g.d.ts.map +1 -0
- package/dist/icrs2g.js +69 -0
- package/dist/icrs2g.js.map +1 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +23 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +32 -0
- package/dist/internal.js.map +1 -0
- package/dist/ir.d.ts +9 -0
- package/dist/ir.d.ts.map +1 -0
- package/dist/ir.js +14 -0
- package/dist/ir.js.map +1 -0
- package/dist/jd2cal.d.ts +31 -0
- package/dist/jd2cal.d.ts.map +1 -0
- package/dist/jd2cal.js +106 -0
- package/dist/jd2cal.js.map +1 -0
- package/dist/jdcalf.d.ts +28 -0
- package/dist/jdcalf.d.ts.map +1 -0
- package/dist/jdcalf.js +84 -0
- package/dist/jdcalf.js.map +1 -0
- package/dist/leap-seconds.d.ts +30 -0
- package/dist/leap-seconds.d.ts.map +1 -0
- package/dist/leap-seconds.js +42 -0
- package/dist/leap-seconds.js.map +1 -0
- package/dist/obl06.d.ts +19 -0
- package/dist/obl06.d.ts.map +1 -0
- package/dist/obl06.js +32 -0
- package/dist/obl06.js.map +1 -0
- package/dist/pap.d.ts +19 -0
- package/dist/pap.d.ts.map +1 -0
- package/dist/pap.js +45 -0
- package/dist/pap.js.map +1 -0
- package/dist/pas.d.ts +17 -0
- package/dist/pas.d.ts.map +1 -0
- package/dist/pas.js +24 -0
- package/dist/pas.js.map +1 -0
- package/dist/pdp.d.ts +8 -0
- package/dist/pdp.d.ts.map +1 -0
- package/dist/pdp.js +9 -0
- package/dist/pdp.js.map +1 -0
- package/dist/pfw06.d.ts +43 -0
- package/dist/pfw06.d.ts.map +1 -0
- package/dist/pfw06.js +73 -0
- package/dist/pfw06.js.map +1 -0
- package/dist/pm.d.ts +8 -0
- package/dist/pm.d.ts.map +1 -0
- package/dist/pm.js +9 -0
- package/dist/pm.js.map +1 -0
- package/dist/pmat06.d.ts +26 -0
- package/dist/pmat06.d.ts.map +1 -0
- package/dist/pmat06.js +34 -0
- package/dist/pmat06.js.map +1 -0
- package/dist/pmp.d.ts +10 -0
- package/dist/pmp.d.ts.map +1 -0
- package/dist/pmp.js +11 -0
- package/dist/pmp.js.map +1 -0
- package/dist/pmpx.d.ts +29 -0
- package/dist/pmpx.d.ts.map +1 -0
- package/dist/pmpx.js +59 -0
- package/dist/pmpx.js.map +1 -0
- package/dist/pmsafe.d.ts +60 -0
- package/dist/pmsafe.d.ts.map +1 -0
- package/dist/pmsafe.js +91 -0
- package/dist/pmsafe.js.map +1 -0
- package/dist/pn.d.ts +12 -0
- package/dist/pn.d.ts.map +1 -0
- package/dist/pn.js +25 -0
- package/dist/pn.js.map +1 -0
- package/dist/ppp.d.ts +10 -0
- package/dist/ppp.d.ts.map +1 -0
- package/dist/ppp.js +11 -0
- package/dist/ppp.js.map +1 -0
- package/dist/ppsp.d.ts +11 -0
- package/dist/ppsp.d.ts.map +1 -0
- package/dist/ppsp.js +17 -0
- package/dist/ppsp.js.map +1 -0
- package/dist/pv2s.d.ts +19 -0
- package/dist/pv2s.d.ts.map +1 -0
- package/dist/pv2s.js +61 -0
- package/dist/pv2s.js.map +1 -0
- package/dist/pvdpv.d.ts +14 -0
- package/dist/pvdpv.d.ts.map +1 -0
- package/dist/pvdpv.js +24 -0
- package/dist/pvdpv.js.map +1 -0
- package/dist/pvm.d.ts +9 -0
- package/dist/pvm.d.ts.map +1 -0
- package/dist/pvm.js +15 -0
- package/dist/pvm.js.map +1 -0
- package/dist/pvmpv.d.ts +10 -0
- package/dist/pvmpv.d.ts.map +1 -0
- package/dist/pvmpv.js +12 -0
- package/dist/pvmpv.js.map +1 -0
- package/dist/pvppv.d.ts +10 -0
- package/dist/pvppv.d.ts.map +1 -0
- package/dist/pvppv.js +12 -0
- package/dist/pvppv.js.map +1 -0
- package/dist/pvstar.d.ts +51 -0
- package/dist/pvstar.d.ts.map +1 -0
- package/dist/pvstar.js +97 -0
- package/dist/pvstar.js.map +1 -0
- package/dist/pvu.d.ts +15 -0
- package/dist/pvu.d.ts.map +1 -0
- package/dist/pvu.js +19 -0
- package/dist/pvu.js.map +1 -0
- package/dist/pvxpv.d.ts +15 -0
- package/dist/pvxpv.d.ts.map +1 -0
- package/dist/pvxpv.js +29 -0
- package/dist/pvxpv.js.map +1 -0
- package/dist/pxp.d.ts +8 -0
- package/dist/pxp.d.ts.map +1 -0
- package/dist/pxp.js +15 -0
- package/dist/pxp.js.map +1 -0
- package/dist/rx.d.ts +21 -0
- package/dist/rx.d.ts.map +1 -0
- package/dist/rx.js +30 -0
- package/dist/rx.js.map +1 -0
- package/dist/rxp.d.ts +10 -0
- package/dist/rxp.d.ts.map +1 -0
- package/dist/rxp.js +21 -0
- package/dist/rxp.js.map +1 -0
- package/dist/rxr.d.ts +10 -0
- package/dist/rxr.d.ts.map +1 -0
- package/dist/rxr.js +27 -0
- package/dist/rxr.js.map +1 -0
- package/dist/ry.d.ts +21 -0
- package/dist/ry.d.ts.map +1 -0
- package/dist/ry.js +30 -0
- package/dist/ry.js.map +1 -0
- package/dist/rz.d.ts +21 -0
- package/dist/rz.d.ts.map +1 -0
- package/dist/rz.js +30 -0
- package/dist/rz.js.map +1 -0
- package/dist/s2c.d.ts +10 -0
- package/dist/s2c.d.ts.map +1 -0
- package/dist/s2c.js +12 -0
- package/dist/s2c.js.map +1 -0
- package/dist/s2pv.d.ts +14 -0
- package/dist/s2pv.d.ts.map +1 -0
- package/dist/s2pv.js +27 -0
- package/dist/s2pv.js.map +1 -0
- package/dist/s2xpv.d.ts +11 -0
- package/dist/s2xpv.d.ts.map +1 -0
- package/dist/s2xpv.js +13 -0
- package/dist/s2xpv.js.map +1 -0
- package/dist/sepp.d.ts +16 -0
- package/dist/sepp.d.ts.map +1 -0
- package/dist/sepp.js +26 -0
- package/dist/sepp.js.map +1 -0
- package/dist/seps.d.ts +11 -0
- package/dist/seps.d.ts.map +1 -0
- package/dist/seps.js +20 -0
- package/dist/seps.js.map +1 -0
- package/dist/starpm.d.ts +56 -0
- package/dist/starpm.d.ts.map +1 -0
- package/dist/starpm.js +90 -0
- package/dist/starpm.js.map +1 -0
- package/dist/starpv.d.ts +62 -0
- package/dist/starpv.d.ts.map +1 -0
- package/dist/starpv.js +147 -0
- package/dist/starpv.js.map +1 -0
- package/dist/sxp.d.ts +10 -0
- package/dist/sxp.d.ts.map +1 -0
- package/dist/sxp.js +11 -0
- package/dist/sxp.js.map +1 -0
- package/dist/sxpv.d.ts +10 -0
- package/dist/sxpv.d.ts.map +1 -0
- package/dist/sxpv.js +12 -0
- package/dist/sxpv.js.map +1 -0
- package/dist/taitt.d.ts +19 -0
- package/dist/taitt.d.ts.map +1 -0
- package/dist/taitt.js +36 -0
- package/dist/taitt.js.map +1 -0
- package/dist/taiut1.d.ts +20 -0
- package/dist/taiut1.d.ts.map +1 -0
- package/dist/taiut1.js +36 -0
- package/dist/taiut1.js.map +1 -0
- package/dist/taiutc.d.ts +33 -0
- package/dist/taiutc.d.ts.map +1 -0
- package/dist/taiutc.js +73 -0
- package/dist/taiutc.js.map +1 -0
- package/dist/tcbtdb.d.ts +29 -0
- package/dist/tcbtdb.d.ts.map +1 -0
- package/dist/tcbtdb.js +51 -0
- package/dist/tcbtdb.js.map +1 -0
- package/dist/tcgtt.d.ts +18 -0
- package/dist/tcgtt.d.ts.map +1 -0
- package/dist/tcgtt.js +35 -0
- package/dist/tcgtt.js.map +1 -0
- package/dist/tdbtcb.d.ts +29 -0
- package/dist/tdbtcb.d.ts.map +1 -0
- package/dist/tdbtcb.js +55 -0
- package/dist/tdbtcb.js.map +1 -0
- package/dist/tdbtt.d.ts +27 -0
- package/dist/tdbtt.d.ts.map +1 -0
- package/dist/tdbtt.js +43 -0
- package/dist/tdbtt.js.map +1 -0
- package/dist/tf2a.d.ts +19 -0
- package/dist/tf2a.d.ts.map +1 -0
- package/dist/tf2a.js +34 -0
- package/dist/tf2a.js.map +1 -0
- package/dist/tr.d.ts +9 -0
- package/dist/tr.d.ts.map +1 -0
- package/dist/tr.js +22 -0
- package/dist/tr.js.map +1 -0
- package/dist/trxp.d.ts +10 -0
- package/dist/trxp.d.ts.map +1 -0
- package/dist/trxp.js +15 -0
- package/dist/trxp.js.map +1 -0
- package/dist/tttai.d.ts +19 -0
- package/dist/tttai.d.ts.map +1 -0
- package/dist/tttai.js +36 -0
- package/dist/tttai.js.map +1 -0
- package/dist/tttcg.d.ts +18 -0
- package/dist/tttcg.d.ts.map +1 -0
- package/dist/tttcg.js +37 -0
- package/dist/tttcg.js.map +1 -0
- package/dist/tttdb.d.ts +27 -0
- package/dist/tttdb.d.ts.map +1 -0
- package/dist/tttdb.js +43 -0
- package/dist/tttdb.js.map +1 -0
- package/dist/ttut1.d.ts +19 -0
- package/dist/ttut1.d.ts.map +1 -0
- package/dist/ttut1.js +35 -0
- package/dist/ttut1.js.map +1 -0
- package/dist/ut1tai.d.ts +20 -0
- package/dist/ut1tai.d.ts.map +1 -0
- package/dist/ut1tai.js +36 -0
- package/dist/ut1tai.js.map +1 -0
- package/dist/ut1tt.d.ts +19 -0
- package/dist/ut1tt.d.ts.map +1 -0
- package/dist/ut1tt.js +35 -0
- package/dist/ut1tt.js.map +1 -0
- package/dist/ut1utc.d.ts +35 -0
- package/dist/ut1utc.d.ts.map +1 -0
- package/dist/ut1utc.js +107 -0
- package/dist/ut1utc.js.map +1 -0
- package/dist/utctai.d.ts +33 -0
- package/dist/utctai.d.ts.map +1 -0
- package/dist/utctai.js +94 -0
- package/dist/utctai.js.map +1 -0
- package/dist/utcut1.d.ts +34 -0
- package/dist/utcut1.d.ts.map +1 -0
- package/dist/utcut1.js +63 -0
- package/dist/utcut1.js.map +1 -0
- package/dist/zp.d.ts +8 -0
- package/dist/zp.d.ts.map +1 -0
- package/dist/zp.js +9 -0
- package/dist/zp.js.map +1 -0
- package/dist/zpv.d.ts +8 -0
- package/dist/zpv.d.ts.map +1 -0
- package/dist/zpv.js +10 -0
- package/dist/zpv.js.map +1 -0
- package/dist/zr.d.ts +9 -0
- package/dist/zr.d.ts.map +1 -0
- package/dist/zr.js +14 -0
- package/dist/zr.js.map +1 -0
- package/package.json +42 -3
- package/src/a2af.ts +48 -0
- package/src/a2tf.ts +45 -0
- package/src/af2a.ts +38 -0
- package/src/anp.ts +15 -0
- package/src/anpm.ts +15 -0
- package/src/bi00.ts +42 -0
- package/src/bp06.ts +51 -0
- package/src/c2s.ts +23 -0
- package/src/cal2jd.ts +67 -0
- package/src/constants.ts +60 -0
- package/src/cp.ts +12 -0
- package/src/cpv.ts +13 -0
- package/src/cr.ts +13 -0
- package/src/d2dtf.ts +153 -0
- package/src/d2tf.ts +87 -0
- package/src/dat.ts +186 -0
- package/src/datini.ts +49 -0
- package/src/dtdb.ts +1110 -0
- package/src/dtf2d.ts +124 -0
- package/src/eceq06.ts +54 -0
- package/src/ecm06.ts +51 -0
- package/src/epb.ts +31 -0
- package/src/epb2jd.ts +21 -0
- package/src/epj.ts +30 -0
- package/src/epj2jd.ts +21 -0
- package/src/eqec06.ts +54 -0
- package/src/era00.ts +54 -0
- package/src/fw2m.ts +64 -0
- package/src/g2icrs.ts +74 -0
- package/src/gmst06.ts +51 -0
- package/src/icrs2g.ts +74 -0
- package/src/index.ts +108 -0
- package/src/internal.ts +46 -0
- package/src/ir.ts +16 -0
- package/src/jd2cal.ts +117 -0
- package/src/jdcalf.ts +93 -0
- package/src/leap-seconds.ts +47 -0
- package/src/obl06.ts +34 -0
- package/src/pap.ts +54 -0
- package/src/pas.ts +25 -0
- package/src/pdp.ts +11 -0
- package/src/pfw06.ts +78 -0
- package/src/pm.ts +11 -0
- package/src/pmat06.ts +37 -0
- package/src/pmp.ts +13 -0
- package/src/pmpx.ts +75 -0
- package/src/pmsafe.ts +109 -0
- package/src/pn.ts +26 -0
- package/src/ppp.ts +13 -0
- package/src/ppsp.ts +20 -0
- package/src/pv2s.ts +71 -0
- package/src/pvdpv.ts +30 -0
- package/src/pvm.ts +19 -0
- package/src/pvmpv.ts +14 -0
- package/src/pvppv.ts +14 -0
- package/src/pvstar.ts +113 -0
- package/src/pvu.ts +20 -0
- package/src/pvxpv.ts +33 -0
- package/src/pxp.ts +17 -0
- package/src/rx.ts +32 -0
- package/src/rxp.ts +24 -0
- package/src/rxr.ts +29 -0
- package/src/ry.ts +32 -0
- package/src/rz.ts +32 -0
- package/src/s2c.ts +14 -0
- package/src/s2pv.ts +30 -0
- package/src/s2xpv.ts +15 -0
- package/src/sepp.ts +28 -0
- package/src/seps.ts +20 -0
- package/src/starpm.ts +108 -0
- package/src/starpv.ts +167 -0
- package/src/sxp.ts +13 -0
- package/src/sxpv.ts +14 -0
- package/src/taitt.ts +38 -0
- package/src/taiut1.ts +41 -0
- package/src/taiutc.ts +76 -0
- package/src/tcbtdb.ts +54 -0
- package/src/tcgtt.ts +37 -0
- package/src/tdbtcb.ts +59 -0
- package/src/tdbtt.ts +48 -0
- package/src/tf2a.ts +38 -0
- package/src/tr.ts +24 -0
- package/src/trxp.ts +18 -0
- package/src/tttai.ts +38 -0
- package/src/tttcg.ts +40 -0
- package/src/tttdb.ts +48 -0
- package/src/ttut1.ts +40 -0
- package/src/ut1tai.ts +41 -0
- package/src/ut1tt.ts +40 -0
- package/src/ut1utc.ts +115 -0
- package/src/utctai.ts +97 -0
- package/src/utcut1.ts +66 -0
- package/src/zp.ts +11 -0
- package/src/zpv.ts +12 -0
- package/src/zr.ts +16 -0
package/src/cal2jd.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraCal2jd (cal2jd.c); see LICENSE.
|
|
2
|
+
import { DJM0 } from './constants.ts'
|
|
3
|
+
import { idiv } from './internal.ts'
|
|
4
|
+
|
|
5
|
+
// Month lengths in days
|
|
6
|
+
const mtab = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] as const
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gregorian Calendar to Julian Date.
|
|
10
|
+
*
|
|
11
|
+
* Notes:
|
|
12
|
+
* 1. The algorithm used is valid from -4800 March 1, but this implementation rejects dates
|
|
13
|
+
* before -4799 January 1.
|
|
14
|
+
* 2. The Julian Date is returned in two pieces, in the usual ERFA manner, which is designed
|
|
15
|
+
* to preserve time resolution. The Julian Date is available as a single number by adding
|
|
16
|
+
* djm0 and djm.
|
|
17
|
+
* 3. In early eras the conversion is from the "Proleptic Gregorian Calendar"; no account is
|
|
18
|
+
* taken of the date(s) of adoption of the Gregorian Calendar, nor is the AD/BC numbering
|
|
19
|
+
* convention observed.
|
|
20
|
+
* 4. The year, month and day are integers in C; C's integer division (truncating toward
|
|
21
|
+
* zero) is kept. Where the JD isn't computed (status -1 or -2), djm0 and djm are NaN.
|
|
22
|
+
*
|
|
23
|
+
* Reference: Explanatory Supplement to the Astronomical Almanac, P. Kenneth Seidelmann
|
|
24
|
+
* (ed), University Science Books (1992), Section 12.92 (p604).
|
|
25
|
+
*
|
|
26
|
+
* @param iy year in Gregorian calendar (Note 1)
|
|
27
|
+
* @param im month in Gregorian calendar (Note 1)
|
|
28
|
+
* @param id day in Gregorian calendar (Note 1)
|
|
29
|
+
* @returns [djm0, djm, status]: MJD zero-point (always 2400000.5), Modified Julian Date for
|
|
30
|
+
* 0 hrs, and status: 0 = OK, -1 = bad year (Note 3: JD not computed), -2 = bad month (JD
|
|
31
|
+
* not computed), -3 = bad day (JD computed)
|
|
32
|
+
*/
|
|
33
|
+
export function cal2jd(
|
|
34
|
+
iy: number,
|
|
35
|
+
im: number,
|
|
36
|
+
id: number,
|
|
37
|
+
): [djm0: number, djm: number, status: number] {
|
|
38
|
+
// Earliest year allowed (4800BC)
|
|
39
|
+
const IYMIN = -4799
|
|
40
|
+
|
|
41
|
+
// Preset status.
|
|
42
|
+
let j = 0
|
|
43
|
+
|
|
44
|
+
// Validate year and month.
|
|
45
|
+
if (iy < IYMIN) return [NaN, NaN, -1]
|
|
46
|
+
if (im < 1 || im > 12) return [NaN, NaN, -2]
|
|
47
|
+
|
|
48
|
+
// If February in a leap year, 1, otherwise 0.
|
|
49
|
+
const ly = im === 2 && !(iy % 4) && (iy % 100 || !(iy % 400)) ? 1 : 0
|
|
50
|
+
|
|
51
|
+
// Validate day, taking into account leap years.
|
|
52
|
+
if (id < 1 || id > mtab[im - 1]! + ly) j = -3
|
|
53
|
+
|
|
54
|
+
// Return result.
|
|
55
|
+
const my = idiv(im - 14, 12)
|
|
56
|
+
const iypmy = iy + my
|
|
57
|
+
const djm0 = DJM0
|
|
58
|
+
const djm =
|
|
59
|
+
idiv(1461 * (iypmy + 4800), 4) +
|
|
60
|
+
idiv(367 * (im - 2 - 12 * my), 12) -
|
|
61
|
+
idiv(3 * idiv(iypmy + 4900, 100), 4) +
|
|
62
|
+
id -
|
|
63
|
+
2432076
|
|
64
|
+
|
|
65
|
+
// Return status.
|
|
66
|
+
return [djm0, djm, j]
|
|
67
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// ERFA's constants (erfam.h), without the ERFA_ prefix. Translated from ERFA 2.0.1; see LICENSE.
|
|
2
|
+
|
|
3
|
+
/** Pi */
|
|
4
|
+
export const DPI = 3.141592653589793238462643
|
|
5
|
+
/** 2Pi */
|
|
6
|
+
export const D2PI = 6.283185307179586476925287
|
|
7
|
+
/** Radians to degrees */
|
|
8
|
+
export const DR2D = 57.29577951308232087679815
|
|
9
|
+
/** Degrees to radians */
|
|
10
|
+
export const DD2R = 1.745329251994329576923691e-2
|
|
11
|
+
/** Radians to arcseconds */
|
|
12
|
+
export const DR2AS = 206264.8062470963551564734
|
|
13
|
+
/** Arcseconds to radians */
|
|
14
|
+
export const DAS2R = 4.848136811095359935899141e-6
|
|
15
|
+
/** Seconds of time to radians */
|
|
16
|
+
export const DS2R = 7.272205216643039903848712e-5
|
|
17
|
+
/** Arcseconds in a full circle */
|
|
18
|
+
export const TURNAS = 1296000.0
|
|
19
|
+
/** Milliarcseconds to radians */
|
|
20
|
+
export const DMAS2R = DAS2R / 1e3
|
|
21
|
+
/** Length of tropical year B1900 (days) */
|
|
22
|
+
export const DTY = 365.242198781
|
|
23
|
+
/** Seconds per day */
|
|
24
|
+
export const DAYSEC = 86400.0
|
|
25
|
+
/** Days per Julian year */
|
|
26
|
+
export const DJY = 365.25
|
|
27
|
+
/** Days per Julian century */
|
|
28
|
+
export const DJC = 36525.0
|
|
29
|
+
/** Days per Julian millennium */
|
|
30
|
+
export const DJM = 365250.0
|
|
31
|
+
/** Reference epoch (J2000.0), Julian Date */
|
|
32
|
+
export const DJ00 = 2451545.0
|
|
33
|
+
/** Julian Date of Modified Julian Date zero */
|
|
34
|
+
export const DJM0 = 2400000.5
|
|
35
|
+
/** Reference epoch (J2000.0), Modified Julian Date */
|
|
36
|
+
export const DJM00 = 51544.5
|
|
37
|
+
/** 1977 Jan 1.0 as MJD */
|
|
38
|
+
export const DJM77 = 43144.0
|
|
39
|
+
/** TT minus TAI (s) */
|
|
40
|
+
export const TTMTAI = 32.184
|
|
41
|
+
/** Astronomical unit (m, IAU 2012) */
|
|
42
|
+
export const DAU = 149597870.7e3
|
|
43
|
+
/** Speed of light (m/s) */
|
|
44
|
+
export const CMPS = 299792458.0
|
|
45
|
+
/** Light time for 1 au (s) */
|
|
46
|
+
export const AULT = DAU / CMPS
|
|
47
|
+
/** Speed of light (au per day) */
|
|
48
|
+
export const DC = DAYSEC / AULT
|
|
49
|
+
/** L_G = 1 - d(TT)/d(TCG) */
|
|
50
|
+
export const ELG = 6.969290134e-10
|
|
51
|
+
/** L_B = 1 - d(TDB)/d(TCB) */
|
|
52
|
+
export const ELB = 1.550519768e-8
|
|
53
|
+
/** TDB (s) at TAI 1977/1/1.0 */
|
|
54
|
+
export const TDB0 = -6.55e-5
|
|
55
|
+
/** Schwarzschild radius of the Sun (au) = 2 * 1.32712440041e20 / (2.99792458e8)^2 / 1.49597870700e11 */
|
|
56
|
+
export const SRS = 1.97412574336e-8
|
|
57
|
+
/** Reference ellipsoids */
|
|
58
|
+
export const WGS84 = 1
|
|
59
|
+
export const GRS80 = 2
|
|
60
|
+
export const WGS72 = 3
|
package/src/cp.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraCp (cp.c); see LICENSE.
|
|
2
|
+
import type { Vec3 } from './internal.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copy a p-vector.
|
|
6
|
+
*
|
|
7
|
+
* @param p p-vector to be copied
|
|
8
|
+
* @returns c: copy
|
|
9
|
+
*/
|
|
10
|
+
export function cp(p: Vec3): Vec3 {
|
|
11
|
+
return [p[0], p[1], p[2]]
|
|
12
|
+
}
|
package/src/cpv.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraCpv (cpv.c); see LICENSE.
|
|
2
|
+
import { cp } from './cp.ts'
|
|
3
|
+
import type { PV } from './internal.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copy a position/velocity vector.
|
|
7
|
+
*
|
|
8
|
+
* @param pv position/velocity vector to be copied
|
|
9
|
+
* @returns c: copy
|
|
10
|
+
*/
|
|
11
|
+
export function cpv(pv: PV): PV {
|
|
12
|
+
return [cp(pv[0]), cp(pv[1])]
|
|
13
|
+
}
|
package/src/cr.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraCr (cr.c); see LICENSE.
|
|
2
|
+
import { cp } from './cp.ts'
|
|
3
|
+
import type { Mat3 } from './internal.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copy an r-matrix.
|
|
7
|
+
*
|
|
8
|
+
* @param r r-matrix to be copied
|
|
9
|
+
* @returns c: copy
|
|
10
|
+
*/
|
|
11
|
+
export function cr(r: Mat3): Mat3 {
|
|
12
|
+
return [cp(r[0]), cp(r[1]), cp(r[2])]
|
|
13
|
+
}
|
package/src/d2dtf.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraD2dtf (d2dtf.c); see LICENSE.
|
|
2
|
+
import { DAYSEC } from './constants.ts'
|
|
3
|
+
import { d2tf } from './d2tf.ts'
|
|
4
|
+
import { dat } from './dat.ts'
|
|
5
|
+
import { jd2cal } from './jd2cal.ts'
|
|
6
|
+
|
|
7
|
+
/** The outputs of an unacceptable date: ERFA leaves them unset. */
|
|
8
|
+
function unacceptable(): ReturnType<typeof d2dtf> {
|
|
9
|
+
return [NaN, NaN, NaN, [NaN, NaN, NaN, NaN], -1]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Format for output a 2-part Julian Date (or in the case of UTC a quasi-JD form that
|
|
14
|
+
* includes special provision for leap seconds).
|
|
15
|
+
*
|
|
16
|
+
* Notes:
|
|
17
|
+
* 1. scale identifies the time scale. Only the value "UTC" (in upper case) is significant,
|
|
18
|
+
* and enables handling of leap seconds (see Note 4). It is compared as C's strcmp does,
|
|
19
|
+
* exactly.
|
|
20
|
+
* 2. ndp is the number of decimal places in the seconds field, and can have negative as well
|
|
21
|
+
* as positive values, such as:
|
|
22
|
+
*
|
|
23
|
+
* ndp resolution
|
|
24
|
+
* -4 1 00 00
|
|
25
|
+
* -3 0 10 00
|
|
26
|
+
* -2 0 01 00
|
|
27
|
+
* -1 0 00 10
|
|
28
|
+
* 0 0 00 01
|
|
29
|
+
* 1 0 00 00.1
|
|
30
|
+
* 2 0 00 00.01
|
|
31
|
+
* 3 0 00 00.001
|
|
32
|
+
*
|
|
33
|
+
* The limits are platform dependent, but a safe range is -5 to +9.
|
|
34
|
+
* 3. d1+d2 is Julian Date, apportioned in any convenient way between the two arguments, for
|
|
35
|
+
* example where d1 is the Julian Day Number and d2 is the fraction of a day. In the case
|
|
36
|
+
* of UTC, where the use of JD is problematical, special conventions apply: see the next
|
|
37
|
+
* note.
|
|
38
|
+
* 4. JD cannot unambiguously represent UTC during a leap second unless special measures are
|
|
39
|
+
* taken. The ERFA internal convention is that the quasi-JD day represents UTC days
|
|
40
|
+
* whether the length is 86399, 86400 or 86401 SI seconds. In the 1960-1972 era there
|
|
41
|
+
* were smaller jumps (in either direction) each time the linear UTC(TAI) expression was
|
|
42
|
+
* changed, and these "mini-leaps" are also included in the ERFA convention.
|
|
43
|
+
* 5. The warning status "dubious year" flags UTCs that predate the introduction of the time
|
|
44
|
+
* scale or that are too far in the future to be trusted. See dat for further details.
|
|
45
|
+
* As in ERFA, the status is that of the last step taken: for UTC, dat for the next day.
|
|
46
|
+
* When the time rounds up to 24h, it is that of finding the next day's date, 0, so the
|
|
47
|
+
* warning is lost.
|
|
48
|
+
* 6. For calendar conventions and limitations, see cal2jd. Where the date is unacceptable
|
|
49
|
+
* (status -1), the outputs are NaN.
|
|
50
|
+
*
|
|
51
|
+
* @param scale time scale ID (Note 1)
|
|
52
|
+
* @param ndp resolution (Note 2)
|
|
53
|
+
* @param d1 time as a 2-part Julian Date (Notes 3, 4)
|
|
54
|
+
* @param d2 time as a 2-part Julian Date (Notes 3, 4)
|
|
55
|
+
* @returns [iy, im, id, ihmsf, status]: year, month, day in Gregorian calendar (Note 6),
|
|
56
|
+
* hours, minutes, seconds, fraction (Note 1), and status: +1 = dubious year (Note 5), 0 =
|
|
57
|
+
* OK, -1 = unacceptable date (Note 6)
|
|
58
|
+
*/
|
|
59
|
+
export function d2dtf(
|
|
60
|
+
scale: string,
|
|
61
|
+
ndp: number,
|
|
62
|
+
d1: number,
|
|
63
|
+
d2: number,
|
|
64
|
+
): [iy: number, im: number, id: number, ihmsf: [number, number, number, number], status: number] {
|
|
65
|
+
let iy1: number, im1: number, id1: number, js: number, iy2: number, im2: number, id2: number
|
|
66
|
+
let fd: number, dat0: number, dat12: number, dat24: number
|
|
67
|
+
|
|
68
|
+
// The two-part JD.
|
|
69
|
+
const a1 = d1
|
|
70
|
+
const b1 = d2
|
|
71
|
+
|
|
72
|
+
// Provisional calendar date.
|
|
73
|
+
;[iy1, im1, id1, fd, js] = jd2cal(a1, b1)
|
|
74
|
+
if (js) return unacceptable()
|
|
75
|
+
|
|
76
|
+
// Is this a leap second day?
|
|
77
|
+
let leap = false
|
|
78
|
+
if (scale === 'UTC') {
|
|
79
|
+
// TAI-UTC at 0h today.
|
|
80
|
+
;[dat0, js] = dat(iy1, im1, id1, 0.0)
|
|
81
|
+
if (js < 0) return unacceptable()
|
|
82
|
+
|
|
83
|
+
// TAI-UTC at 12h today (to detect drift).
|
|
84
|
+
;[dat12, js] = dat(iy1, im1, id1, 0.5)
|
|
85
|
+
if (js < 0) return unacceptable()
|
|
86
|
+
|
|
87
|
+
// TAI-UTC at 0h tomorrow (to detect jumps).
|
|
88
|
+
;[iy2, im2, id2, , js] = jd2cal(a1 + 1.5, b1 - fd)
|
|
89
|
+
if (js) return unacceptable()
|
|
90
|
+
;[dat24, js] = dat(iy2, im2, id2, 0.0)
|
|
91
|
+
if (js < 0) return unacceptable()
|
|
92
|
+
|
|
93
|
+
// Any sudden change in TAI-UTC (seconds).
|
|
94
|
+
const dleap = dat24 - (2.0 * dat12 - dat0)
|
|
95
|
+
|
|
96
|
+
// If leap second day, scale the fraction of a day into SI.
|
|
97
|
+
leap = Math.abs(dleap) > 0.5
|
|
98
|
+
if (leap) fd += fd * dleap / DAYSEC
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Provisional time of day.
|
|
102
|
+
const [, ihmsf1] = d2tf(ndp, fd)
|
|
103
|
+
|
|
104
|
+
// Has the (rounded) time gone past 24h?
|
|
105
|
+
if (ihmsf1[0] > 23) {
|
|
106
|
+
// Yes. We probably need tomorrow's calendar date.
|
|
107
|
+
;[iy2, im2, id2, , js] = jd2cal(a1 + 1.5, b1 - fd)
|
|
108
|
+
if (js) return unacceptable()
|
|
109
|
+
|
|
110
|
+
// Is today a leap second day?
|
|
111
|
+
if (!leap) {
|
|
112
|
+
// No. Use 0h tomorrow.
|
|
113
|
+
iy1 = iy2
|
|
114
|
+
im1 = im2
|
|
115
|
+
id1 = id2
|
|
116
|
+
ihmsf1[0] = 0
|
|
117
|
+
ihmsf1[1] = 0
|
|
118
|
+
ihmsf1[2] = 0
|
|
119
|
+
} else {
|
|
120
|
+
// Yes. Are we past the leap second itself?
|
|
121
|
+
if (ihmsf1[2] > 0) {
|
|
122
|
+
// Yes. Use tomorrow but allow for the leap second.
|
|
123
|
+
iy1 = iy2
|
|
124
|
+
im1 = im2
|
|
125
|
+
id1 = id2
|
|
126
|
+
ihmsf1[0] = 0
|
|
127
|
+
ihmsf1[1] = 0
|
|
128
|
+
ihmsf1[2] = 0
|
|
129
|
+
} else {
|
|
130
|
+
// No. Use 23 59 60... today.
|
|
131
|
+
ihmsf1[0] = 23
|
|
132
|
+
ihmsf1[1] = 59
|
|
133
|
+
ihmsf1[2] = 60
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// If rounding to 10s or coarser always go up to new day.
|
|
137
|
+
if (ndp < 0 && ihmsf1[2] === 60) {
|
|
138
|
+
iy1 = iy2
|
|
139
|
+
im1 = im2
|
|
140
|
+
id1 = id2
|
|
141
|
+
ihmsf1[0] = 0
|
|
142
|
+
ihmsf1[1] = 0
|
|
143
|
+
ihmsf1[2] = 0
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Results.
|
|
149
|
+
const ihmsf: [number, number, number, number] = [ihmsf1[0], ihmsf1[1], ihmsf1[2], ihmsf1[3]]
|
|
150
|
+
|
|
151
|
+
// Status.
|
|
152
|
+
return [iy1, im1, id1, ihmsf, js]
|
|
153
|
+
}
|
package/src/d2tf.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraD2tf (d2tf.c); see LICENSE.
|
|
2
|
+
import { DAYSEC } from './constants.ts'
|
|
3
|
+
import { dint, dnint } from './internal.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Decompose days to hours, minutes, seconds, fraction.
|
|
7
|
+
*
|
|
8
|
+
* Notes:
|
|
9
|
+
* 1. The argument ndp is interpreted as follows:
|
|
10
|
+
*
|
|
11
|
+
* ndp resolution
|
|
12
|
+
* : ...0000 00 00
|
|
13
|
+
* -7 1000 00 00
|
|
14
|
+
* -6 100 00 00
|
|
15
|
+
* -5 10 00 00
|
|
16
|
+
* -4 1 00 00
|
|
17
|
+
* -3 0 10 00
|
|
18
|
+
* -2 0 01 00
|
|
19
|
+
* -1 0 00 10
|
|
20
|
+
* 0 0 00 01
|
|
21
|
+
* 1 0 00 00.1
|
|
22
|
+
* 2 0 00 00.01
|
|
23
|
+
* 3 0 00 00.001
|
|
24
|
+
* : 0 00 00.000...
|
|
25
|
+
*
|
|
26
|
+
* 2. The largest positive useful value for ndp is determined by the size of days, the format
|
|
27
|
+
* of double on the target platform, and the risk of overflowing ihmsf[3]. On a typical
|
|
28
|
+
* platform, for days up to 1.0, the available floating-point precision might correspond
|
|
29
|
+
* to ndp=12. In C the practical limit is typically ndp=9, set by the capacity of a
|
|
30
|
+
* 32-bit int; here the fields are numbers, exact as integers up to 2^53.
|
|
31
|
+
* 3. The absolute value of days may exceed 1.0. In cases where it does not, it is up to the
|
|
32
|
+
* caller to test for and handle the case where days is very nearly 1.0 and rounds up to
|
|
33
|
+
* 24 hours, by testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
|
|
34
|
+
*
|
|
35
|
+
* @param ndp resolution (Note 1)
|
|
36
|
+
* @param days interval in days
|
|
37
|
+
* @returns [sign, ihmsf]: '+' or '-', and hours, minutes, seconds, fraction
|
|
38
|
+
*/
|
|
39
|
+
export function d2tf(
|
|
40
|
+
ndp: number,
|
|
41
|
+
days: number,
|
|
42
|
+
): [sign: '+' | '-', ihmsf: [number, number, number, number]] {
|
|
43
|
+
let nrs: number, rs: number
|
|
44
|
+
|
|
45
|
+
// Handle sign.
|
|
46
|
+
const sign = days >= 0.0 ? '+' : '-'
|
|
47
|
+
|
|
48
|
+
// Interval in seconds.
|
|
49
|
+
let a = DAYSEC * Math.abs(days)
|
|
50
|
+
|
|
51
|
+
// Pre-round if resolution coarser than 1s (then pretend ndp=1).
|
|
52
|
+
if (ndp < 0) {
|
|
53
|
+
nrs = 1
|
|
54
|
+
for (let n = 1; n <= -ndp; n++) {
|
|
55
|
+
nrs *= n === 2 || n === 4 ? 6 : 10
|
|
56
|
+
}
|
|
57
|
+
rs = nrs
|
|
58
|
+
const w = a / rs
|
|
59
|
+
a = rs * dnint(w)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Express the unit of each field in resolution units.
|
|
63
|
+
nrs = 1
|
|
64
|
+
for (let n = 1; n <= ndp; n++) {
|
|
65
|
+
nrs *= 10
|
|
66
|
+
}
|
|
67
|
+
rs = nrs
|
|
68
|
+
const rm = rs * 60.0
|
|
69
|
+
const rh = rm * 60.0
|
|
70
|
+
|
|
71
|
+
// Round the interval and express in resolution units.
|
|
72
|
+
a = dnint(rs * a)
|
|
73
|
+
|
|
74
|
+
// Break into fields.
|
|
75
|
+
let ah = a / rh
|
|
76
|
+
ah = dint(ah)
|
|
77
|
+
a -= ah * rh
|
|
78
|
+
let am = a / rm
|
|
79
|
+
am = dint(am)
|
|
80
|
+
a -= am * rm
|
|
81
|
+
let as = a / rs
|
|
82
|
+
as = dint(as)
|
|
83
|
+
const af = a - as * rs
|
|
84
|
+
|
|
85
|
+
// Return results.
|
|
86
|
+
return [sign, [ah, am, as, af]]
|
|
87
|
+
}
|
package/src/dat.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraDat (dat.c); see LICENSE.
|
|
2
|
+
import { cal2jd } from './cal2jd.ts'
|
|
3
|
+
import { datini } from './datini.ts'
|
|
4
|
+
import type { LeapSecond } from './datini.ts'
|
|
5
|
+
|
|
6
|
+
// Release year for this version of eraDat
|
|
7
|
+
const IYV = 2023
|
|
8
|
+
|
|
9
|
+
// Reference dates (MJD) and drift rates (s/day), pre leap seconds
|
|
10
|
+
const drift: readonly (readonly [number, number])[] = [
|
|
11
|
+
[37300.0, 0.0012960],
|
|
12
|
+
[37300.0, 0.0012960],
|
|
13
|
+
[37300.0, 0.0012960],
|
|
14
|
+
[37665.0, 0.0011232],
|
|
15
|
+
[37665.0, 0.0011232],
|
|
16
|
+
[38761.0, 0.0012960],
|
|
17
|
+
[38761.0, 0.0012960],
|
|
18
|
+
[38761.0, 0.0012960],
|
|
19
|
+
[38761.0, 0.0012960],
|
|
20
|
+
[38761.0, 0.0012960],
|
|
21
|
+
[38761.0, 0.0012960],
|
|
22
|
+
[38761.0, 0.0012960],
|
|
23
|
+
[39126.0, 0.0025920],
|
|
24
|
+
[39126.0, 0.0025920],
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
// Number of Delta(AT) expressions before leap seconds were introduced
|
|
28
|
+
const NERA1 = drift.length
|
|
29
|
+
|
|
30
|
+
// Dates and Delta(AT)s
|
|
31
|
+
const _changes: readonly LeapSecond[] = [
|
|
32
|
+
{ iyear: 1960, month: 1, delat: 1.4178180 },
|
|
33
|
+
{ iyear: 1961, month: 1, delat: 1.4228180 },
|
|
34
|
+
{ iyear: 1961, month: 8, delat: 1.3728180 },
|
|
35
|
+
{ iyear: 1962, month: 1, delat: 1.8458580 },
|
|
36
|
+
{ iyear: 1963, month: 11, delat: 1.9458580 },
|
|
37
|
+
{ iyear: 1964, month: 1, delat: 3.2401300 },
|
|
38
|
+
{ iyear: 1964, month: 4, delat: 3.3401300 },
|
|
39
|
+
{ iyear: 1964, month: 9, delat: 3.4401300 },
|
|
40
|
+
{ iyear: 1965, month: 1, delat: 3.5401300 },
|
|
41
|
+
{ iyear: 1965, month: 3, delat: 3.6401300 },
|
|
42
|
+
{ iyear: 1965, month: 7, delat: 3.7401300 },
|
|
43
|
+
{ iyear: 1965, month: 9, delat: 3.8401300 },
|
|
44
|
+
{ iyear: 1966, month: 1, delat: 4.3131700 },
|
|
45
|
+
{ iyear: 1968, month: 2, delat: 4.2131700 },
|
|
46
|
+
{ iyear: 1972, month: 1, delat: 10.0 },
|
|
47
|
+
{ iyear: 1972, month: 7, delat: 11.0 },
|
|
48
|
+
{ iyear: 1973, month: 1, delat: 12.0 },
|
|
49
|
+
{ iyear: 1974, month: 1, delat: 13.0 },
|
|
50
|
+
{ iyear: 1975, month: 1, delat: 14.0 },
|
|
51
|
+
{ iyear: 1976, month: 1, delat: 15.0 },
|
|
52
|
+
{ iyear: 1977, month: 1, delat: 16.0 },
|
|
53
|
+
{ iyear: 1978, month: 1, delat: 17.0 },
|
|
54
|
+
{ iyear: 1979, month: 1, delat: 18.0 },
|
|
55
|
+
{ iyear: 1980, month: 1, delat: 19.0 },
|
|
56
|
+
{ iyear: 1981, month: 7, delat: 20.0 },
|
|
57
|
+
{ iyear: 1982, month: 7, delat: 21.0 },
|
|
58
|
+
{ iyear: 1983, month: 7, delat: 22.0 },
|
|
59
|
+
{ iyear: 1985, month: 7, delat: 23.0 },
|
|
60
|
+
{ iyear: 1988, month: 1, delat: 24.0 },
|
|
61
|
+
{ iyear: 1990, month: 1, delat: 25.0 },
|
|
62
|
+
{ iyear: 1991, month: 1, delat: 26.0 },
|
|
63
|
+
{ iyear: 1992, month: 7, delat: 27.0 },
|
|
64
|
+
{ iyear: 1993, month: 7, delat: 28.0 },
|
|
65
|
+
{ iyear: 1994, month: 7, delat: 29.0 },
|
|
66
|
+
{ iyear: 1996, month: 1, delat: 30.0 },
|
|
67
|
+
{ iyear: 1997, month: 7, delat: 31.0 },
|
|
68
|
+
{ iyear: 1999, month: 1, delat: 32.0 },
|
|
69
|
+
{ iyear: 2006, month: 1, delat: 33.0 },
|
|
70
|
+
{ iyear: 2009, month: 1, delat: 34.0 },
|
|
71
|
+
{ iyear: 2012, month: 7, delat: 35.0 },
|
|
72
|
+
{ iyear: 2015, month: 7, delat: 36.0 },
|
|
73
|
+
{ iyear: 2017, month: 1, delat: 37.0 },
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
// Number of Delta(AT) changes
|
|
77
|
+
const _NDAT = _changes.length
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* For a given UTC date, calculate Delta(AT) = TAI-UTC.
|
|
81
|
+
*
|
|
82
|
+
* IMPORTANT: a new version of this function must be produced whenever a new leap second is
|
|
83
|
+
* announced (latest leap second: 2016 December 31), with a new line in the table of changes
|
|
84
|
+
* and IYV set to the current year. Between releases, setLeapSeconds replaces the table at
|
|
85
|
+
* run time, as pyerfa and Astropy do.
|
|
86
|
+
*
|
|
87
|
+
* Notes:
|
|
88
|
+
* 1. UTC began at 1960 January 1.0 (JD 2436934.5) and it is improper to call the function
|
|
89
|
+
* with an earlier date. If this is attempted, zero is returned together with a warning
|
|
90
|
+
* status. Because leap seconds cannot, in principle, be predicted in advance, a reliable
|
|
91
|
+
* check for dates beyond the valid range is impossible. To guard against gross errors, a
|
|
92
|
+
* year five or more after the release year of the present function (IYV, 2023) is
|
|
93
|
+
* considered dubious: from 2029 on. In this case a warning status is returned but the
|
|
94
|
+
* result is computed in the normal way. For both too-early and too-late years, the
|
|
95
|
+
* warning status is +1. This is distinct from the error status -1, which signifies a year
|
|
96
|
+
* so early that JD could not be computed. "Too early" is before the first year of the
|
|
97
|
+
* table in use.
|
|
98
|
+
* 2. If the specified date is for a day which ends with a leap second, the TAI-UTC value
|
|
99
|
+
* returned is for the period leading up to the leap second. If the date is for a day
|
|
100
|
+
* which begins as a leap second ends, the TAI-UTC returned is for the period following
|
|
101
|
+
* the leap second.
|
|
102
|
+
* 3. The day number must be in the normal calendar range, for example 1 through 30 for
|
|
103
|
+
* April. The "almanac" convention of allowing such dates as January 0 and December 32 is
|
|
104
|
+
* not supported in this function, in order to avoid confusion near leap seconds.
|
|
105
|
+
* 4. The fraction of day is used only for dates before the introduction of leap seconds, the
|
|
106
|
+
* first of which occurred at the end of 1971. It is tested for validity (0 to 1 is the
|
|
107
|
+
* valid range) even if not used; if invalid, zero is used and status -4 is returned. For
|
|
108
|
+
* many applications, setting fd to zero is acceptable; the resulting error is always less
|
|
109
|
+
* than 3 ms (and occurs only pre-1972).
|
|
110
|
+
* 5. The status value returned in the case where there are multiple errors refers to the
|
|
111
|
+
* first error detected. For example, if the month and day are 13 and 32 respectively,
|
|
112
|
+
* status -2 (bad month) will be returned. The "internal error" status refers to a case
|
|
113
|
+
* that is impossible with the built-in table.
|
|
114
|
+
* 6. In cases where a valid result is not available, zero is returned.
|
|
115
|
+
* 7. The pre-1972 drift applies to the first 14 rows of the table in use, whatever it holds:
|
|
116
|
+
* a replacement table (setLeapSeconds) must keep the built-in table's first 14 rows.
|
|
117
|
+
*
|
|
118
|
+
* References:
|
|
119
|
+
* - For dates from 1961 January 1 onwards, the expressions from the file
|
|
120
|
+
* ftp://maia.usno.navy.mil/ser7/tai-utc.dat are used.
|
|
121
|
+
* - The 5ms timestep at 1961 January 1 is taken from 2.58.1 (p87) of the 1992 Explanatory
|
|
122
|
+
* Supplement.
|
|
123
|
+
*
|
|
124
|
+
* @param iy UTC: year (Notes 1 and 2)
|
|
125
|
+
* @param im month (Note 2)
|
|
126
|
+
* @param id day (Notes 2 and 3)
|
|
127
|
+
* @param fd fraction of day (Note 4)
|
|
128
|
+
* @returns [deltat, status]: TAI minus UTC in seconds, and status (Note 5): 1 = dubious
|
|
129
|
+
* year (Note 1), 0 = OK, -1 = bad year, -2 = bad month, -3 = bad day (Note 3), -4 = bad
|
|
130
|
+
* fraction (Note 4), -5 = internal error (Note 5)
|
|
131
|
+
*/
|
|
132
|
+
export function dat(
|
|
133
|
+
iy: number,
|
|
134
|
+
im: number,
|
|
135
|
+
id: number,
|
|
136
|
+
fd: number,
|
|
137
|
+
): [deltat: number, status: number] {
|
|
138
|
+
// Get/initialise leap-second if needed
|
|
139
|
+
const [NDAT, changes] = datini(_changes, _NDAT)
|
|
140
|
+
|
|
141
|
+
// Miscellaneous local variables
|
|
142
|
+
let i: number
|
|
143
|
+
|
|
144
|
+
// Initialize the result to zero.
|
|
145
|
+
let da = 0.0
|
|
146
|
+
let deltat = da
|
|
147
|
+
|
|
148
|
+
// If invalid fraction of a day, set error status and give up.
|
|
149
|
+
if (fd < 0.0 || fd > 1.0) return [deltat, -4]
|
|
150
|
+
|
|
151
|
+
// Convert the date into an MJD.
|
|
152
|
+
const [, djm, js] = cal2jd(iy, im, id)
|
|
153
|
+
let j = js
|
|
154
|
+
|
|
155
|
+
// If invalid year, month, or day, give up.
|
|
156
|
+
if (j < 0) return [deltat, j]
|
|
157
|
+
|
|
158
|
+
// If pre-UTC year, set warning status and give up.
|
|
159
|
+
if (iy < changes[0]!.iyear) return [deltat, 1]
|
|
160
|
+
|
|
161
|
+
// If suspiciously late year, set warning status but proceed.
|
|
162
|
+
if (iy > IYV + 5) j = 1
|
|
163
|
+
|
|
164
|
+
// Combine year and month to form a date-ordered integer...
|
|
165
|
+
const m = 12 * iy + im
|
|
166
|
+
|
|
167
|
+
// ...and use it to find the preceding table entry.
|
|
168
|
+
for (i = NDAT - 1; i >= 0; i--) {
|
|
169
|
+
if (m >= 12 * changes[i]!.iyear + changes[i]!.month) break
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Prevent underflow warnings.
|
|
173
|
+
if (i < 0) return [deltat, -5]
|
|
174
|
+
|
|
175
|
+
// Get the Delta(AT).
|
|
176
|
+
da = changes[i]!.delat
|
|
177
|
+
|
|
178
|
+
// If pre-1972, adjust for drift.
|
|
179
|
+
if (i < NERA1) da += (djm + fd - drift[i]![0]) * drift[i]![1]
|
|
180
|
+
|
|
181
|
+
// Return the Delta(AT) value.
|
|
182
|
+
deltat = da
|
|
183
|
+
|
|
184
|
+
// Return the status.
|
|
185
|
+
return [deltat, j]
|
|
186
|
+
}
|
package/src/datini.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Translated from ERFA 2.0.1 eraDatini, with the table eraSetLeapSeconds sets and
|
|
2
|
+
// eraGetLeapSeconds reads (erfadatextra.c, not derived from SOFA); see LICENSE.
|
|
3
|
+
//
|
|
4
|
+
// Internal: the leap-second table in use. dat reads it through datini; leap-seconds.ts gets
|
|
5
|
+
// and sets it. Kept apart from both so that dat and leap-seconds.ts don't import each other.
|
|
6
|
+
// Not exported from the package, except the LeapSecond type.
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A row of a leap-second table (eraLEAPSECOND): from the start of month `month` of year
|
|
10
|
+
* `iyear`, TAI-UTC is `delat` seconds. Before 1972, dat adds a drift to the first rows.
|
|
11
|
+
*/
|
|
12
|
+
export type LeapSecond = { iyear: number; month: number; delat: number }
|
|
13
|
+
|
|
14
|
+
// The table in use and its number of entries. NDAT <= 0 means the built-in table, which
|
|
15
|
+
// datini installs on dat's next call.
|
|
16
|
+
let changes: readonly LeapSecond[] = []
|
|
17
|
+
let NDAT = -1
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* eraSetLeapSeconds: use this table. A count <= 0 causes a reset of the table to the
|
|
21
|
+
* built-in version. No sanity checks are performed.
|
|
22
|
+
*/
|
|
23
|
+
export function setTable(leapseconds: readonly LeapSecond[], count: number): void {
|
|
24
|
+
changes = leapseconds
|
|
25
|
+
NDAT = count
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The table in use and its number of entries, as eraGetLeapSeconds reads them. */
|
|
29
|
+
export function getTable(): [NDAT: number, leapseconds: readonly LeapSecond[]] {
|
|
30
|
+
return [NDAT, changes]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get the leap second table, initializing it to the built-in version if necessary. For dat
|
|
35
|
+
* only.
|
|
36
|
+
*
|
|
37
|
+
* @param builtin the built-in table
|
|
38
|
+
* @param nBuiltin its number of entries
|
|
39
|
+
* @returns [NDAT, leapseconds]: the number of entries, and the table in use
|
|
40
|
+
*/
|
|
41
|
+
export function datini(
|
|
42
|
+
builtin: readonly LeapSecond[],
|
|
43
|
+
nBuiltin: number,
|
|
44
|
+
): [NDAT: number, leapseconds: readonly LeapSecond[]] {
|
|
45
|
+
if (NDAT <= 0) {
|
|
46
|
+
setTable(builtin, nBuiltin)
|
|
47
|
+
}
|
|
48
|
+
return [NDAT, changes]
|
|
49
|
+
}
|