@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.
Files changed (478) hide show
  1. package/LICENSE +56 -0
  2. package/README.md +109 -2
  3. package/dist/a2af.d.ts +36 -0
  4. package/dist/a2af.d.ts.map +1 -0
  5. package/dist/a2af.js +44 -0
  6. package/dist/a2af.js.map +1 -0
  7. package/dist/a2tf.d.ts +36 -0
  8. package/dist/a2tf.d.ts.map +1 -0
  9. package/dist/a2tf.js +42 -0
  10. package/dist/a2tf.js.map +1 -0
  11. package/dist/af2a.d.ts +19 -0
  12. package/dist/af2a.d.ts.map +1 -0
  13. package/dist/af2a.js +34 -0
  14. package/dist/af2a.js.map +1 -0
  15. package/dist/anp.d.ts +8 -0
  16. package/dist/anp.d.ts.map +1 -0
  17. package/dist/anp.js +16 -0
  18. package/dist/anp.js.map +1 -0
  19. package/dist/anpm.d.ts +8 -0
  20. package/dist/anpm.d.ts.map +1 -0
  21. package/dist/anpm.js +16 -0
  22. package/dist/anpm.js.map +1 -0
  23. package/dist/bi00.d.ts +27 -0
  24. package/dist/bi00.d.ts.map +1 -0
  25. package/dist/bi00.js +40 -0
  26. package/dist/bi00.js.map +1 -0
  27. package/dist/bp06.d.ts +27 -0
  28. package/dist/bp06.d.ts.map +1 -0
  29. package/dist/bp06.js +46 -0
  30. package/dist/bp06.js.map +1 -0
  31. package/dist/c2s.d.ts +14 -0
  32. package/dist/c2s.d.ts.map +1 -0
  33. package/dist/c2s.js +21 -0
  34. package/dist/c2s.js.map +1 -0
  35. package/dist/cal2jd.d.ts +27 -0
  36. package/dist/cal2jd.d.ts.map +1 -0
  37. package/dist/cal2jd.js +58 -0
  38. package/dist/cal2jd.js.map +1 -0
  39. package/dist/constants.d.ts +59 -0
  40. package/dist/constants.d.ts.map +1 -0
  41. package/dist/constants.js +60 -0
  42. package/dist/constants.js.map +1 -0
  43. package/dist/cp.d.ts +9 -0
  44. package/dist/cp.d.ts.map +1 -0
  45. package/dist/cp.js +10 -0
  46. package/dist/cp.js.map +1 -0
  47. package/dist/cpv.d.ts +9 -0
  48. package/dist/cpv.d.ts.map +1 -0
  49. package/dist/cpv.js +12 -0
  50. package/dist/cpv.js.map +1 -0
  51. package/dist/cr.d.ts +9 -0
  52. package/dist/cr.d.ts.map +1 -0
  53. package/dist/cr.js +12 -0
  54. package/dist/cr.js.map +1 -0
  55. package/dist/d2dtf.d.ts +49 -0
  56. package/dist/d2dtf.d.ts.map +1 -0
  57. package/dist/d2dtf.js +142 -0
  58. package/dist/d2dtf.js.map +1 -0
  59. package/dist/d2tf.d.ts +36 -0
  60. package/dist/d2tf.d.ts.map +1 -0
  61. package/dist/d2tf.js +77 -0
  62. package/dist/d2tf.js.map +1 -0
  63. package/dist/dat.d.ts +55 -0
  64. package/dist/dat.d.ts.map +1 -0
  65. package/dist/dat.js +168 -0
  66. package/dist/dat.js.map +1 -0
  67. package/dist/datini.d.ts +26 -0
  68. package/dist/datini.d.ts.map +1 -0
  69. package/dist/datini.js +37 -0
  70. package/dist/datini.js.map +1 -0
  71. package/dist/dtdb.d.ts +105 -0
  72. package/dist/dtdb.d.ts.map +1 -0
  73. package/dist/dtdb.js +1076 -0
  74. package/dist/dtdb.js.map +1 -0
  75. package/dist/dtf2d.d.ts +45 -0
  76. package/dist/dtf2d.d.ts.map +1 -0
  77. package/dist/dtf2d.js +112 -0
  78. package/dist/dtf2d.js.map +1 -0
  79. package/dist/eceq06.d.ts +24 -0
  80. package/dist/eceq06.d.ts.map +1 -0
  81. package/dist/eceq06.js +44 -0
  82. package/dist/eceq06.js.map +1 -0
  83. package/dist/ecm06.d.ts +30 -0
  84. package/dist/ecm06.d.ts.map +1 -0
  85. package/dist/ecm06.js +45 -0
  86. package/dist/ecm06.js.map +1 -0
  87. package/dist/epb.d.ts +24 -0
  88. package/dist/epb.d.ts.map +1 -0
  89. package/dist/epb.js +30 -0
  90. package/dist/epb.js.map +1 -0
  91. package/dist/epb2jd.d.ts +14 -0
  92. package/dist/epb2jd.d.ts.map +1 -0
  93. package/dist/epb2jd.js +20 -0
  94. package/dist/epb2jd.js.map +1 -0
  95. package/dist/epj.d.ts +24 -0
  96. package/dist/epj.d.ts.map +1 -0
  97. package/dist/epj.js +29 -0
  98. package/dist/epj.js.map +1 -0
  99. package/dist/epj2jd.d.ts +14 -0
  100. package/dist/epj2jd.d.ts.map +1 -0
  101. package/dist/epj2jd.js +20 -0
  102. package/dist/epj2jd.js.map +1 -0
  103. package/dist/eqec06.d.ts +24 -0
  104. package/dist/eqec06.d.ts.map +1 -0
  105. package/dist/eqec06.js +44 -0
  106. package/dist/eqec06.js.map +1 -0
  107. package/dist/era00.d.ts +29 -0
  108. package/dist/era00.d.ts.map +1 -0
  109. package/dist/era00.js +51 -0
  110. package/dist/era00.js.map +1 -0
  111. package/dist/fw2m.d.ts +51 -0
  112. package/dist/fw2m.d.ts.map +1 -0
  113. package/dist/fw2m.js +61 -0
  114. package/dist/fw2m.js.map +1 -0
  115. package/dist/g2icrs.d.ts +33 -0
  116. package/dist/g2icrs.d.ts.map +1 -0
  117. package/dist/g2icrs.js +69 -0
  118. package/dist/g2icrs.js.map +1 -0
  119. package/dist/gmst06.d.ts +32 -0
  120. package/dist/gmst06.d.ts.map +1 -0
  121. package/dist/gmst06.js +49 -0
  122. package/dist/gmst06.js.map +1 -0
  123. package/dist/icrs2g.d.ts +33 -0
  124. package/dist/icrs2g.d.ts.map +1 -0
  125. package/dist/icrs2g.js +69 -0
  126. package/dist/icrs2g.js.map +1 -0
  127. package/dist/index.d.ts +95 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +106 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/internal.d.ts +23 -0
  132. package/dist/internal.d.ts.map +1 -0
  133. package/dist/internal.js +32 -0
  134. package/dist/internal.js.map +1 -0
  135. package/dist/ir.d.ts +9 -0
  136. package/dist/ir.d.ts.map +1 -0
  137. package/dist/ir.js +14 -0
  138. package/dist/ir.js.map +1 -0
  139. package/dist/jd2cal.d.ts +31 -0
  140. package/dist/jd2cal.d.ts.map +1 -0
  141. package/dist/jd2cal.js +106 -0
  142. package/dist/jd2cal.js.map +1 -0
  143. package/dist/jdcalf.d.ts +28 -0
  144. package/dist/jdcalf.d.ts.map +1 -0
  145. package/dist/jdcalf.js +84 -0
  146. package/dist/jdcalf.js.map +1 -0
  147. package/dist/leap-seconds.d.ts +30 -0
  148. package/dist/leap-seconds.d.ts.map +1 -0
  149. package/dist/leap-seconds.js +42 -0
  150. package/dist/leap-seconds.js.map +1 -0
  151. package/dist/obl06.d.ts +19 -0
  152. package/dist/obl06.d.ts.map +1 -0
  153. package/dist/obl06.js +32 -0
  154. package/dist/obl06.js.map +1 -0
  155. package/dist/pap.d.ts +19 -0
  156. package/dist/pap.d.ts.map +1 -0
  157. package/dist/pap.js +45 -0
  158. package/dist/pap.js.map +1 -0
  159. package/dist/pas.d.ts +17 -0
  160. package/dist/pas.d.ts.map +1 -0
  161. package/dist/pas.js +24 -0
  162. package/dist/pas.js.map +1 -0
  163. package/dist/pdp.d.ts +8 -0
  164. package/dist/pdp.d.ts.map +1 -0
  165. package/dist/pdp.js +9 -0
  166. package/dist/pdp.js.map +1 -0
  167. package/dist/pfw06.d.ts +43 -0
  168. package/dist/pfw06.d.ts.map +1 -0
  169. package/dist/pfw06.js +73 -0
  170. package/dist/pfw06.js.map +1 -0
  171. package/dist/pm.d.ts +8 -0
  172. package/dist/pm.d.ts.map +1 -0
  173. package/dist/pm.js +9 -0
  174. package/dist/pm.js.map +1 -0
  175. package/dist/pmat06.d.ts +26 -0
  176. package/dist/pmat06.d.ts.map +1 -0
  177. package/dist/pmat06.js +34 -0
  178. package/dist/pmat06.js.map +1 -0
  179. package/dist/pmp.d.ts +10 -0
  180. package/dist/pmp.d.ts.map +1 -0
  181. package/dist/pmp.js +11 -0
  182. package/dist/pmp.js.map +1 -0
  183. package/dist/pmpx.d.ts +29 -0
  184. package/dist/pmpx.d.ts.map +1 -0
  185. package/dist/pmpx.js +59 -0
  186. package/dist/pmpx.js.map +1 -0
  187. package/dist/pmsafe.d.ts +60 -0
  188. package/dist/pmsafe.d.ts.map +1 -0
  189. package/dist/pmsafe.js +91 -0
  190. package/dist/pmsafe.js.map +1 -0
  191. package/dist/pn.d.ts +12 -0
  192. package/dist/pn.d.ts.map +1 -0
  193. package/dist/pn.js +25 -0
  194. package/dist/pn.js.map +1 -0
  195. package/dist/ppp.d.ts +10 -0
  196. package/dist/ppp.d.ts.map +1 -0
  197. package/dist/ppp.js +11 -0
  198. package/dist/ppp.js.map +1 -0
  199. package/dist/ppsp.d.ts +11 -0
  200. package/dist/ppsp.d.ts.map +1 -0
  201. package/dist/ppsp.js +17 -0
  202. package/dist/ppsp.js.map +1 -0
  203. package/dist/pv2s.d.ts +19 -0
  204. package/dist/pv2s.d.ts.map +1 -0
  205. package/dist/pv2s.js +61 -0
  206. package/dist/pv2s.js.map +1 -0
  207. package/dist/pvdpv.d.ts +14 -0
  208. package/dist/pvdpv.d.ts.map +1 -0
  209. package/dist/pvdpv.js +24 -0
  210. package/dist/pvdpv.js.map +1 -0
  211. package/dist/pvm.d.ts +9 -0
  212. package/dist/pvm.d.ts.map +1 -0
  213. package/dist/pvm.js +15 -0
  214. package/dist/pvm.js.map +1 -0
  215. package/dist/pvmpv.d.ts +10 -0
  216. package/dist/pvmpv.d.ts.map +1 -0
  217. package/dist/pvmpv.js +12 -0
  218. package/dist/pvmpv.js.map +1 -0
  219. package/dist/pvppv.d.ts +10 -0
  220. package/dist/pvppv.d.ts.map +1 -0
  221. package/dist/pvppv.js +12 -0
  222. package/dist/pvppv.js.map +1 -0
  223. package/dist/pvstar.d.ts +51 -0
  224. package/dist/pvstar.d.ts.map +1 -0
  225. package/dist/pvstar.js +97 -0
  226. package/dist/pvstar.js.map +1 -0
  227. package/dist/pvu.d.ts +15 -0
  228. package/dist/pvu.d.ts.map +1 -0
  229. package/dist/pvu.js +19 -0
  230. package/dist/pvu.js.map +1 -0
  231. package/dist/pvxpv.d.ts +15 -0
  232. package/dist/pvxpv.d.ts.map +1 -0
  233. package/dist/pvxpv.js +29 -0
  234. package/dist/pvxpv.js.map +1 -0
  235. package/dist/pxp.d.ts +8 -0
  236. package/dist/pxp.d.ts.map +1 -0
  237. package/dist/pxp.js +15 -0
  238. package/dist/pxp.js.map +1 -0
  239. package/dist/rx.d.ts +21 -0
  240. package/dist/rx.d.ts.map +1 -0
  241. package/dist/rx.js +30 -0
  242. package/dist/rx.js.map +1 -0
  243. package/dist/rxp.d.ts +10 -0
  244. package/dist/rxp.d.ts.map +1 -0
  245. package/dist/rxp.js +21 -0
  246. package/dist/rxp.js.map +1 -0
  247. package/dist/rxr.d.ts +10 -0
  248. package/dist/rxr.d.ts.map +1 -0
  249. package/dist/rxr.js +27 -0
  250. package/dist/rxr.js.map +1 -0
  251. package/dist/ry.d.ts +21 -0
  252. package/dist/ry.d.ts.map +1 -0
  253. package/dist/ry.js +30 -0
  254. package/dist/ry.js.map +1 -0
  255. package/dist/rz.d.ts +21 -0
  256. package/dist/rz.d.ts.map +1 -0
  257. package/dist/rz.js +30 -0
  258. package/dist/rz.js.map +1 -0
  259. package/dist/s2c.d.ts +10 -0
  260. package/dist/s2c.d.ts.map +1 -0
  261. package/dist/s2c.js +12 -0
  262. package/dist/s2c.js.map +1 -0
  263. package/dist/s2pv.d.ts +14 -0
  264. package/dist/s2pv.d.ts.map +1 -0
  265. package/dist/s2pv.js +27 -0
  266. package/dist/s2pv.js.map +1 -0
  267. package/dist/s2xpv.d.ts +11 -0
  268. package/dist/s2xpv.d.ts.map +1 -0
  269. package/dist/s2xpv.js +13 -0
  270. package/dist/s2xpv.js.map +1 -0
  271. package/dist/sepp.d.ts +16 -0
  272. package/dist/sepp.d.ts.map +1 -0
  273. package/dist/sepp.js +26 -0
  274. package/dist/sepp.js.map +1 -0
  275. package/dist/seps.d.ts +11 -0
  276. package/dist/seps.d.ts.map +1 -0
  277. package/dist/seps.js +20 -0
  278. package/dist/seps.js.map +1 -0
  279. package/dist/starpm.d.ts +56 -0
  280. package/dist/starpm.d.ts.map +1 -0
  281. package/dist/starpm.js +90 -0
  282. package/dist/starpm.js.map +1 -0
  283. package/dist/starpv.d.ts +62 -0
  284. package/dist/starpv.d.ts.map +1 -0
  285. package/dist/starpv.js +147 -0
  286. package/dist/starpv.js.map +1 -0
  287. package/dist/sxp.d.ts +10 -0
  288. package/dist/sxp.d.ts.map +1 -0
  289. package/dist/sxp.js +11 -0
  290. package/dist/sxp.js.map +1 -0
  291. package/dist/sxpv.d.ts +10 -0
  292. package/dist/sxpv.d.ts.map +1 -0
  293. package/dist/sxpv.js +12 -0
  294. package/dist/sxpv.js.map +1 -0
  295. package/dist/taitt.d.ts +19 -0
  296. package/dist/taitt.d.ts.map +1 -0
  297. package/dist/taitt.js +36 -0
  298. package/dist/taitt.js.map +1 -0
  299. package/dist/taiut1.d.ts +20 -0
  300. package/dist/taiut1.d.ts.map +1 -0
  301. package/dist/taiut1.js +36 -0
  302. package/dist/taiut1.js.map +1 -0
  303. package/dist/taiutc.d.ts +33 -0
  304. package/dist/taiutc.d.ts.map +1 -0
  305. package/dist/taiutc.js +73 -0
  306. package/dist/taiutc.js.map +1 -0
  307. package/dist/tcbtdb.d.ts +29 -0
  308. package/dist/tcbtdb.d.ts.map +1 -0
  309. package/dist/tcbtdb.js +51 -0
  310. package/dist/tcbtdb.js.map +1 -0
  311. package/dist/tcgtt.d.ts +18 -0
  312. package/dist/tcgtt.d.ts.map +1 -0
  313. package/dist/tcgtt.js +35 -0
  314. package/dist/tcgtt.js.map +1 -0
  315. package/dist/tdbtcb.d.ts +29 -0
  316. package/dist/tdbtcb.d.ts.map +1 -0
  317. package/dist/tdbtcb.js +55 -0
  318. package/dist/tdbtcb.js.map +1 -0
  319. package/dist/tdbtt.d.ts +27 -0
  320. package/dist/tdbtt.d.ts.map +1 -0
  321. package/dist/tdbtt.js +43 -0
  322. package/dist/tdbtt.js.map +1 -0
  323. package/dist/tf2a.d.ts +19 -0
  324. package/dist/tf2a.d.ts.map +1 -0
  325. package/dist/tf2a.js +34 -0
  326. package/dist/tf2a.js.map +1 -0
  327. package/dist/tr.d.ts +9 -0
  328. package/dist/tr.d.ts.map +1 -0
  329. package/dist/tr.js +22 -0
  330. package/dist/tr.js.map +1 -0
  331. package/dist/trxp.d.ts +10 -0
  332. package/dist/trxp.d.ts.map +1 -0
  333. package/dist/trxp.js +15 -0
  334. package/dist/trxp.js.map +1 -0
  335. package/dist/tttai.d.ts +19 -0
  336. package/dist/tttai.d.ts.map +1 -0
  337. package/dist/tttai.js +36 -0
  338. package/dist/tttai.js.map +1 -0
  339. package/dist/tttcg.d.ts +18 -0
  340. package/dist/tttcg.d.ts.map +1 -0
  341. package/dist/tttcg.js +37 -0
  342. package/dist/tttcg.js.map +1 -0
  343. package/dist/tttdb.d.ts +27 -0
  344. package/dist/tttdb.d.ts.map +1 -0
  345. package/dist/tttdb.js +43 -0
  346. package/dist/tttdb.js.map +1 -0
  347. package/dist/ttut1.d.ts +19 -0
  348. package/dist/ttut1.d.ts.map +1 -0
  349. package/dist/ttut1.js +35 -0
  350. package/dist/ttut1.js.map +1 -0
  351. package/dist/ut1tai.d.ts +20 -0
  352. package/dist/ut1tai.d.ts.map +1 -0
  353. package/dist/ut1tai.js +36 -0
  354. package/dist/ut1tai.js.map +1 -0
  355. package/dist/ut1tt.d.ts +19 -0
  356. package/dist/ut1tt.d.ts.map +1 -0
  357. package/dist/ut1tt.js +35 -0
  358. package/dist/ut1tt.js.map +1 -0
  359. package/dist/ut1utc.d.ts +35 -0
  360. package/dist/ut1utc.d.ts.map +1 -0
  361. package/dist/ut1utc.js +107 -0
  362. package/dist/ut1utc.js.map +1 -0
  363. package/dist/utctai.d.ts +33 -0
  364. package/dist/utctai.d.ts.map +1 -0
  365. package/dist/utctai.js +94 -0
  366. package/dist/utctai.js.map +1 -0
  367. package/dist/utcut1.d.ts +34 -0
  368. package/dist/utcut1.d.ts.map +1 -0
  369. package/dist/utcut1.js +63 -0
  370. package/dist/utcut1.js.map +1 -0
  371. package/dist/zp.d.ts +8 -0
  372. package/dist/zp.d.ts.map +1 -0
  373. package/dist/zp.js +9 -0
  374. package/dist/zp.js.map +1 -0
  375. package/dist/zpv.d.ts +8 -0
  376. package/dist/zpv.d.ts.map +1 -0
  377. package/dist/zpv.js +10 -0
  378. package/dist/zpv.js.map +1 -0
  379. package/dist/zr.d.ts +9 -0
  380. package/dist/zr.d.ts.map +1 -0
  381. package/dist/zr.js +14 -0
  382. package/dist/zr.js.map +1 -0
  383. package/package.json +42 -3
  384. package/src/a2af.ts +48 -0
  385. package/src/a2tf.ts +45 -0
  386. package/src/af2a.ts +38 -0
  387. package/src/anp.ts +15 -0
  388. package/src/anpm.ts +15 -0
  389. package/src/bi00.ts +42 -0
  390. package/src/bp06.ts +51 -0
  391. package/src/c2s.ts +23 -0
  392. package/src/cal2jd.ts +67 -0
  393. package/src/constants.ts +60 -0
  394. package/src/cp.ts +12 -0
  395. package/src/cpv.ts +13 -0
  396. package/src/cr.ts +13 -0
  397. package/src/d2dtf.ts +153 -0
  398. package/src/d2tf.ts +87 -0
  399. package/src/dat.ts +186 -0
  400. package/src/datini.ts +49 -0
  401. package/src/dtdb.ts +1110 -0
  402. package/src/dtf2d.ts +124 -0
  403. package/src/eceq06.ts +54 -0
  404. package/src/ecm06.ts +51 -0
  405. package/src/epb.ts +31 -0
  406. package/src/epb2jd.ts +21 -0
  407. package/src/epj.ts +30 -0
  408. package/src/epj2jd.ts +21 -0
  409. package/src/eqec06.ts +54 -0
  410. package/src/era00.ts +54 -0
  411. package/src/fw2m.ts +64 -0
  412. package/src/g2icrs.ts +74 -0
  413. package/src/gmst06.ts +51 -0
  414. package/src/icrs2g.ts +74 -0
  415. package/src/index.ts +108 -0
  416. package/src/internal.ts +46 -0
  417. package/src/ir.ts +16 -0
  418. package/src/jd2cal.ts +117 -0
  419. package/src/jdcalf.ts +93 -0
  420. package/src/leap-seconds.ts +47 -0
  421. package/src/obl06.ts +34 -0
  422. package/src/pap.ts +54 -0
  423. package/src/pas.ts +25 -0
  424. package/src/pdp.ts +11 -0
  425. package/src/pfw06.ts +78 -0
  426. package/src/pm.ts +11 -0
  427. package/src/pmat06.ts +37 -0
  428. package/src/pmp.ts +13 -0
  429. package/src/pmpx.ts +75 -0
  430. package/src/pmsafe.ts +109 -0
  431. package/src/pn.ts +26 -0
  432. package/src/ppp.ts +13 -0
  433. package/src/ppsp.ts +20 -0
  434. package/src/pv2s.ts +71 -0
  435. package/src/pvdpv.ts +30 -0
  436. package/src/pvm.ts +19 -0
  437. package/src/pvmpv.ts +14 -0
  438. package/src/pvppv.ts +14 -0
  439. package/src/pvstar.ts +113 -0
  440. package/src/pvu.ts +20 -0
  441. package/src/pvxpv.ts +33 -0
  442. package/src/pxp.ts +17 -0
  443. package/src/rx.ts +32 -0
  444. package/src/rxp.ts +24 -0
  445. package/src/rxr.ts +29 -0
  446. package/src/ry.ts +32 -0
  447. package/src/rz.ts +32 -0
  448. package/src/s2c.ts +14 -0
  449. package/src/s2pv.ts +30 -0
  450. package/src/s2xpv.ts +15 -0
  451. package/src/sepp.ts +28 -0
  452. package/src/seps.ts +20 -0
  453. package/src/starpm.ts +108 -0
  454. package/src/starpv.ts +167 -0
  455. package/src/sxp.ts +13 -0
  456. package/src/sxpv.ts +14 -0
  457. package/src/taitt.ts +38 -0
  458. package/src/taiut1.ts +41 -0
  459. package/src/taiutc.ts +76 -0
  460. package/src/tcbtdb.ts +54 -0
  461. package/src/tcgtt.ts +37 -0
  462. package/src/tdbtcb.ts +59 -0
  463. package/src/tdbtt.ts +48 -0
  464. package/src/tf2a.ts +38 -0
  465. package/src/tr.ts +24 -0
  466. package/src/trxp.ts +18 -0
  467. package/src/tttai.ts +38 -0
  468. package/src/tttcg.ts +40 -0
  469. package/src/tttdb.ts +48 -0
  470. package/src/ttut1.ts +40 -0
  471. package/src/ut1tai.ts +41 -0
  472. package/src/ut1tt.ts +40 -0
  473. package/src/ut1utc.ts +115 -0
  474. package/src/utctai.ts +97 -0
  475. package/src/utcut1.ts +66 -0
  476. package/src/zp.ts +11 -0
  477. package/src/zpv.ts +12 -0
  478. 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
+ }
@@ -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
+ }