@interstellar-tools/temporal 1.0.0 → 1.1.1
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/README.md +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/time-scales.d.ts +124 -0
- package/dist/time-scales.d.ts.map +1 -0
- package/dist/time-scales.js +192 -0
- package/dist/time-scales.js.map +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# @interstellar-tools/temporal
|
|
2
2
|
|
|
3
3
|
Time and epoch utilities for space applications, from attoseconds to gigayears,
|
|
4
|
-
with unit normalisation and conversion that the rest of the stack builds on
|
|
4
|
+
with unit normalisation and conversion that the rest of the stack builds on, and
|
|
5
|
+
Julian dates on the UTC, TAI, TT and UT1 time scales, with leap seconds.
|
|
5
6
|
|
|
6
7
|
## Documentation
|
|
7
8
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAE3C,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAE3C,cAAc,8BAA8B,CAAC;AAE7C,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAE3C,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAE3C,cAAc,8BAA8B,CAAC;AAE7C,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { TimeScaleType } from '@interstellar-tools/types';
|
|
2
|
+
/**
|
|
3
|
+
* **TAI − UTC**, in **s**, at a moment: the number of leap seconds so far, plus
|
|
4
|
+
* the 10 s UTC started with in 1972.
|
|
5
|
+
*
|
|
6
|
+
* $$
|
|
7
|
+
* \mathrm{TAI} = \mathrm{UTC} + \Delta_{\mathrm{AT}},
|
|
8
|
+
* \qquad
|
|
9
|
+
* \mathrm{TT} = \mathrm{TAI} + 32.184\ \mathrm{s}
|
|
10
|
+
* $$
|
|
11
|
+
*
|
|
12
|
+
* Where:
|
|
13
|
+
* - $ \Delta_{\mathrm{AT}} $ is TAI − UTC, from the leap second table `LEAP_SECONDS` (s)
|
|
14
|
+
*
|
|
15
|
+
* ::: info Notes
|
|
16
|
+
*
|
|
17
|
+
* - The table in `@interstellar-tools/constants` holds the leap seconds the
|
|
18
|
+
* IERS has announced. A moment after a leap second that isn't in it yet gets
|
|
19
|
+
* an offset 1 s short: keep the package up to date.
|
|
20
|
+
* - A JavaScript `Date` can't hold 23:59:60, the leap second itself: it goes
|
|
21
|
+
* from 23:59:59.999 to 00:00:00 of the next day, where the new offset starts.
|
|
22
|
+
*
|
|
23
|
+
* :::
|
|
24
|
+
*
|
|
25
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01).
|
|
26
|
+
* @returns TAI − UTC in **s**: a whole number, 37 since 2017.
|
|
27
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
28
|
+
* @throws {RangeError} If `date` is before 1972-01-01.
|
|
29
|
+
* @group Time scales
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* taiMinusUtc(new Date('2016-12-31T23:59:59Z')); // 36
|
|
34
|
+
* taiMinusUtc(new Date('2017-01-01T00:00:00Z')); // 37
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const taiMinusUtc: (date: Date) => number;
|
|
38
|
+
/**
|
|
39
|
+
* The **Julian date** of a moment, in a time scale: the number of days since
|
|
40
|
+
* noon on 1 January 4713 BC, counted on that scale's clock.
|
|
41
|
+
*
|
|
42
|
+
* $$
|
|
43
|
+
* \mathrm{JD} = \frac{t_{\mathrm{Unix}} + \Delta}{86\,400\,000} + 2\,440\,587.5
|
|
44
|
+
* $$
|
|
45
|
+
*
|
|
46
|
+
* Where:
|
|
47
|
+
* - $ t_{\mathrm{Unix}} $ is the `Date`'s milliseconds since 1970-01-01T00:00:00Z (ms)
|
|
48
|
+
* - $ \Delta $ is the scale's lead over UTC: 0 for UTC and UT1, TAI − UTC for TAI, and TAI − UTC + 32.184 s for TT (ms)
|
|
49
|
+
*
|
|
50
|
+
* ::: info Notes
|
|
51
|
+
*
|
|
52
|
+
* - **UT1 is taken as UTC.** They differ by up to 0.9 s; the exact difference
|
|
53
|
+
* is measured and published by the IERS, and the library fetches nothing.
|
|
54
|
+
* - A Julian date as a double is precise to about 40 µs today.
|
|
55
|
+
* - UTC Julian dates step over leap seconds, like the `Date` itself: the
|
|
56
|
+
* difference between two of them in days can be 1 s short. Take differences
|
|
57
|
+
* in TAI or TT.
|
|
58
|
+
*
|
|
59
|
+
* :::
|
|
60
|
+
*
|
|
61
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01 for TAI and TT).
|
|
62
|
+
* @param scale - The time scale to count in. Defaults to `UTC`.
|
|
63
|
+
* @returns The Julian date in **days**.
|
|
64
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
65
|
+
* @throws {RangeError} If `scale` is not a {@link TimeScaleType}, or `date` is before 1972-01-01 for TAI and TT.
|
|
66
|
+
* @group Time scales
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { J2000_UTC } from '@interstellar-tools/constants';
|
|
71
|
+
*
|
|
72
|
+
* julianDate(J2000_UTC, 'TT'); // 2451545: J2000 is JD 2451545.0 TT
|
|
73
|
+
* julianDate(J2000_UTC); // 2451544.999257: 64.184 s earlier on the UTC clock
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare const julianDate: (date: Date, scale?: TimeScaleType) => number;
|
|
77
|
+
/**
|
|
78
|
+
* The **modified Julian date** of a moment, in a time scale: the Julian date
|
|
79
|
+
* minus 2 400 000.5, so days start at midnight and MJD 0 is 1858-11-17.
|
|
80
|
+
*
|
|
81
|
+
* $$
|
|
82
|
+
* \mathrm{MJD} = \mathrm{JD} - 2\,400\,000.5
|
|
83
|
+
* $$
|
|
84
|
+
*
|
|
85
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01 for TAI and TT).
|
|
86
|
+
* @param scale - The time scale to count in. Defaults to `UTC`.
|
|
87
|
+
* @returns The modified Julian date in **days**.
|
|
88
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
89
|
+
* @throws {RangeError} If `scale` is not a {@link TimeScaleType}, or `date` is before 1972-01-01 for TAI and TT.
|
|
90
|
+
* @group Time scales
|
|
91
|
+
* @see {@link julianDate}
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* modifiedJulianDate(new Date('2000-01-01T00:00:00Z')); // 51544
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare const modifiedJulianDate: (date: Date, scale?: TimeScaleType) => number;
|
|
99
|
+
/**
|
|
100
|
+
* The **UTC `Date`** of a Julian date in a time scale: the inverse of
|
|
101
|
+
* {@link julianDate}.
|
|
102
|
+
*
|
|
103
|
+
* ::: info Notes
|
|
104
|
+
*
|
|
105
|
+
* - The result is rounded to the millisecond, the precision of a `Date`.
|
|
106
|
+
* - A TAI or TT Julian date that falls inside a leap second, 23:59:60 UTC,
|
|
107
|
+
* has no `Date`: it becomes 00:00:00 of the next day.
|
|
108
|
+
*
|
|
109
|
+
* :::
|
|
110
|
+
*
|
|
111
|
+
* @param jd - The Julian date in **days** (finite).
|
|
112
|
+
* @param scale - The time scale the Julian date counts in. Defaults to `UTC`.
|
|
113
|
+
* @returns The moment as a `Date`.
|
|
114
|
+
* @throws {TypeError} If `jd` is not a finite number.
|
|
115
|
+
* @throws {RangeError} If `scale` is not a {@link TimeScaleType}, the moment is before 1972-01-01 for TAI and TT, or it's outside the range of a `Date`.
|
|
116
|
+
* @group Time scales
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* dateFromJulianDate(2451545, 'TT').toISOString(); // '2000-01-01T11:58:55.816Z'
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare const dateFromJulianDate: (jd: number, scale?: TimeScaleType) => Date;
|
|
124
|
+
//# sourceMappingURL=time-scales.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-scales.d.ts","sourceRoot":"","sources":["../src/time-scales.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AA8C/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,MACR,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,IAAI,EACV,QAAO,aAAqB,KAC3B,MASF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,kBAAkB,GAC7B,MAAM,IAAI,EACV,QAAO,aAAqB,KAC3B,MAUF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,kBAAkB,GAC7B,IAAI,MAAM,EACV,QAAO,aAAqB,KAC3B,IAmCF,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { JULIAN_DATE_UNIX_EPOCH, LEAP_SECONDS, MILLISECONDS_PER_DAY, MODIFIED_JULIAN_DATE_OFFSET, TT_MINUS_TAI_SECONDS } from '@interstellar-tools/constants';
|
|
2
|
+
// The leap second table as Unix milliseconds, for lookups
|
|
3
|
+
const STEPS = LEAP_SECONDS.map(({ date, taiMinusUtc }) => ({
|
|
4
|
+
ms: Date.parse(`${date}T00:00:00Z`),
|
|
5
|
+
taiMinusUtc
|
|
6
|
+
}));
|
|
7
|
+
const SCALES = ['UTC', 'TAI', 'TT', 'UT1'];
|
|
8
|
+
const assertDate = (date) => {
|
|
9
|
+
if (!(date instanceof Date) || !Number.isFinite(date.getTime()))
|
|
10
|
+
throw new TypeError(`date must be a valid Date. Received: ${String(date)}`);
|
|
11
|
+
return date.getTime();
|
|
12
|
+
};
|
|
13
|
+
const assertScale = (scale) => {
|
|
14
|
+
if (!SCALES.includes(scale))
|
|
15
|
+
throw new RangeError(`scale must be one of ${SCALES.join(', ')}. Received: ${String(scale)}`);
|
|
16
|
+
};
|
|
17
|
+
// TAI − UTC in s at a UTC instant in Unix ms
|
|
18
|
+
const leapSecondsAt = (ms) => {
|
|
19
|
+
if (ms < STEPS[0].ms)
|
|
20
|
+
throw new RangeError(`TAI and TT are only defined here from 1972-01-01, when UTC began to step by whole leap seconds. Received: ${new Date(ms).toISOString()}`);
|
|
21
|
+
let taiMinusUtc = STEPS[0].taiMinusUtc;
|
|
22
|
+
for (const step of STEPS) {
|
|
23
|
+
if (ms < step.ms)
|
|
24
|
+
break;
|
|
25
|
+
taiMinusUtc = step.taiMinusUtc;
|
|
26
|
+
}
|
|
27
|
+
return taiMinusUtc;
|
|
28
|
+
};
|
|
29
|
+
// The scale's lead over UTC, in ms, at a UTC instant in Unix ms
|
|
30
|
+
const leadOverUtc = (ms, scale) => {
|
|
31
|
+
if (scale === 'UTC' || scale === 'UT1')
|
|
32
|
+
return 0;
|
|
33
|
+
const tai = 1000 * leapSecondsAt(ms);
|
|
34
|
+
return scale === 'TT' ? tai + 1000 * TT_MINUS_TAI_SECONDS : tai;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* **TAI − UTC**, in **s**, at a moment: the number of leap seconds so far, plus
|
|
38
|
+
* the 10 s UTC started with in 1972.
|
|
39
|
+
*
|
|
40
|
+
* $$
|
|
41
|
+
* \mathrm{TAI} = \mathrm{UTC} + \Delta_{\mathrm{AT}},
|
|
42
|
+
* \qquad
|
|
43
|
+
* \mathrm{TT} = \mathrm{TAI} + 32.184\ \mathrm{s}
|
|
44
|
+
* $$
|
|
45
|
+
*
|
|
46
|
+
* Where:
|
|
47
|
+
* - $ \Delta_{\mathrm{AT}} $ is TAI − UTC, from the leap second table `LEAP_SECONDS` (s)
|
|
48
|
+
*
|
|
49
|
+
* ::: info Notes
|
|
50
|
+
*
|
|
51
|
+
* - The table in `@interstellar-tools/constants` holds the leap seconds the
|
|
52
|
+
* IERS has announced. A moment after a leap second that isn't in it yet gets
|
|
53
|
+
* an offset 1 s short: keep the package up to date.
|
|
54
|
+
* - A JavaScript `Date` can't hold 23:59:60, the leap second itself: it goes
|
|
55
|
+
* from 23:59:59.999 to 00:00:00 of the next day, where the new offset starts.
|
|
56
|
+
*
|
|
57
|
+
* :::
|
|
58
|
+
*
|
|
59
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01).
|
|
60
|
+
* @returns TAI − UTC in **s**: a whole number, 37 since 2017.
|
|
61
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
62
|
+
* @throws {RangeError} If `date` is before 1972-01-01.
|
|
63
|
+
* @group Time scales
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* taiMinusUtc(new Date('2016-12-31T23:59:59Z')); // 36
|
|
68
|
+
* taiMinusUtc(new Date('2017-01-01T00:00:00Z')); // 37
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export const taiMinusUtc = (date) => leapSecondsAt(assertDate(date));
|
|
72
|
+
/**
|
|
73
|
+
* The **Julian date** of a moment, in a time scale: the number of days since
|
|
74
|
+
* noon on 1 January 4713 BC, counted on that scale's clock.
|
|
75
|
+
*
|
|
76
|
+
* $$
|
|
77
|
+
* \mathrm{JD} = \frac{t_{\mathrm{Unix}} + \Delta}{86\,400\,000} + 2\,440\,587.5
|
|
78
|
+
* $$
|
|
79
|
+
*
|
|
80
|
+
* Where:
|
|
81
|
+
* - $ t_{\mathrm{Unix}} $ is the `Date`'s milliseconds since 1970-01-01T00:00:00Z (ms)
|
|
82
|
+
* - $ \Delta $ is the scale's lead over UTC: 0 for UTC and UT1, TAI − UTC for TAI, and TAI − UTC + 32.184 s for TT (ms)
|
|
83
|
+
*
|
|
84
|
+
* ::: info Notes
|
|
85
|
+
*
|
|
86
|
+
* - **UT1 is taken as UTC.** They differ by up to 0.9 s; the exact difference
|
|
87
|
+
* is measured and published by the IERS, and the library fetches nothing.
|
|
88
|
+
* - A Julian date as a double is precise to about 40 µs today.
|
|
89
|
+
* - UTC Julian dates step over leap seconds, like the `Date` itself: the
|
|
90
|
+
* difference between two of them in days can be 1 s short. Take differences
|
|
91
|
+
* in TAI or TT.
|
|
92
|
+
*
|
|
93
|
+
* :::
|
|
94
|
+
*
|
|
95
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01 for TAI and TT).
|
|
96
|
+
* @param scale - The time scale to count in. Defaults to `UTC`.
|
|
97
|
+
* @returns The Julian date in **days**.
|
|
98
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
99
|
+
* @throws {RangeError} If `scale` is not a {@link TimeScaleType}, or `date` is before 1972-01-01 for TAI and TT.
|
|
100
|
+
* @group Time scales
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { J2000_UTC } from '@interstellar-tools/constants';
|
|
105
|
+
*
|
|
106
|
+
* julianDate(J2000_UTC, 'TT'); // 2451545: J2000 is JD 2451545.0 TT
|
|
107
|
+
* julianDate(J2000_UTC); // 2451544.999257: 64.184 s earlier on the UTC clock
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export const julianDate = (date, scale = 'UTC') => {
|
|
111
|
+
const ms = assertDate(date);
|
|
112
|
+
assertScale(scale);
|
|
113
|
+
return ((ms + leadOverUtc(ms, scale)) / MILLISECONDS_PER_DAY +
|
|
114
|
+
JULIAN_DATE_UNIX_EPOCH);
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* The **modified Julian date** of a moment, in a time scale: the Julian date
|
|
118
|
+
* minus 2 400 000.5, so days start at midnight and MJD 0 is 1858-11-17.
|
|
119
|
+
*
|
|
120
|
+
* $$
|
|
121
|
+
* \mathrm{MJD} = \mathrm{JD} - 2\,400\,000.5
|
|
122
|
+
* $$
|
|
123
|
+
*
|
|
124
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01 for TAI and TT).
|
|
125
|
+
* @param scale - The time scale to count in. Defaults to `UTC`.
|
|
126
|
+
* @returns The modified Julian date in **days**.
|
|
127
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
128
|
+
* @throws {RangeError} If `scale` is not a {@link TimeScaleType}, or `date` is before 1972-01-01 for TAI and TT.
|
|
129
|
+
* @group Time scales
|
|
130
|
+
* @see {@link julianDate}
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* modifiedJulianDate(new Date('2000-01-01T00:00:00Z')); // 51544
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export const modifiedJulianDate = (date, scale = 'UTC') => {
|
|
138
|
+
const ms = assertDate(date);
|
|
139
|
+
assertScale(scale);
|
|
140
|
+
// Subtract the offsets first, so the result keeps its precision
|
|
141
|
+
return ((ms + leadOverUtc(ms, scale)) / MILLISECONDS_PER_DAY +
|
|
142
|
+
(JULIAN_DATE_UNIX_EPOCH - MODIFIED_JULIAN_DATE_OFFSET));
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* The **UTC `Date`** of a Julian date in a time scale: the inverse of
|
|
146
|
+
* {@link julianDate}.
|
|
147
|
+
*
|
|
148
|
+
* ::: info Notes
|
|
149
|
+
*
|
|
150
|
+
* - The result is rounded to the millisecond, the precision of a `Date`.
|
|
151
|
+
* - A TAI or TT Julian date that falls inside a leap second, 23:59:60 UTC,
|
|
152
|
+
* has no `Date`: it becomes 00:00:00 of the next day.
|
|
153
|
+
*
|
|
154
|
+
* :::
|
|
155
|
+
*
|
|
156
|
+
* @param jd - The Julian date in **days** (finite).
|
|
157
|
+
* @param scale - The time scale the Julian date counts in. Defaults to `UTC`.
|
|
158
|
+
* @returns The moment as a `Date`.
|
|
159
|
+
* @throws {TypeError} If `jd` is not a finite number.
|
|
160
|
+
* @throws {RangeError} If `scale` is not a {@link TimeScaleType}, the moment is before 1972-01-01 for TAI and TT, or it's outside the range of a `Date`.
|
|
161
|
+
* @group Time scales
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* dateFromJulianDate(2451545, 'TT').toISOString(); // '2000-01-01T11:58:55.816Z'
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export const dateFromJulianDate = (jd, scale = 'UTC') => {
|
|
169
|
+
if (!Number.isFinite(jd))
|
|
170
|
+
throw new TypeError(`jd must be a finite number. Received: ${jd}`);
|
|
171
|
+
assertScale(scale);
|
|
172
|
+
// Milliseconds since 1970-01-01T00:00:00 on the scale's clock
|
|
173
|
+
const onScale = Math.round((jd - JULIAN_DATE_UNIX_EPOCH) * MILLISECONDS_PER_DAY);
|
|
174
|
+
let ms = onScale;
|
|
175
|
+
if (scale === 'TAI' || scale === 'TT') {
|
|
176
|
+
// The leap seconds depend on the UTC moment: guess with the scale's own
|
|
177
|
+
// time, then settle on the offset at the guess
|
|
178
|
+
const tai = scale === 'TT' ? onScale - 1000 * TT_MINUS_TAI_SECONDS : onScale;
|
|
179
|
+
const guess = tai - 1000 * leapSecondsAt(tai);
|
|
180
|
+
const offset = leapSecondsAt(guess);
|
|
181
|
+
ms = tai - 1000 * offset;
|
|
182
|
+
// Inside a leap second, no UTC moment has this offset: take the start of
|
|
183
|
+
// the next day, where the new offset begins
|
|
184
|
+
if (leapSecondsAt(ms) !== offset)
|
|
185
|
+
ms = STEPS.find((step) => step.ms > guess).ms;
|
|
186
|
+
}
|
|
187
|
+
const date = new Date(ms);
|
|
188
|
+
if (!Number.isFinite(date.getTime()))
|
|
189
|
+
throw new RangeError(`jd is outside the range of a Date. Received: ${jd}`);
|
|
190
|
+
return date;
|
|
191
|
+
};
|
|
192
|
+
//# sourceMappingURL=time-scales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-scales.js","sourceRoot":"","sources":["../src/time-scales.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,oBAAoB,EACpB,2BAA2B,EAC3B,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AAGvC,0DAA0D;AAC1D,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;IACzD,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,YAAY,CAAC;IACnC,WAAW;CACZ,CAAC,CAAC,CAAC;AACJ,MAAM,MAAM,GAA6B,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACrE,MAAM,UAAU,GAAG,CAAC,IAAU,EAAU,EAAE;IACxC,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7D,MAAM,IAAI,SAAS,CAAC,wCAAwC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC,CA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K,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACtC,wEAAwE;QACxE,+CAA+C;QAC/C,MAAM,GAAG,GACP,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC;QACnE,MAAM,KAAK,GAAG,GAAG,GAAG,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QAEpC,EAAE,GAAG,GAAG,GAAG,IAAI,GAAG,MAAM,CAAC;QAEzB,yEAAyE;QACzE,4CAA4C;QAC5C,IAAI,aAAa,CAAC,EAAE,CAAC,KAAK,MAAM;YAC9B,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAE,CAAC,EAAE,CAAC;IACnD,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;IAE1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAClC,MAAM,IAAI,UAAU,CAAC,gDAAgD,EAAE,EAAE,CAAC,CAAC;IAE7E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interstellar-tools/temporal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Time and epoch utilities for space applications (e.g., building blocks toward Julian dates, conversions, and ephemeris-friendly time handling).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"temporal",
|
|
@@ -109,11 +109,11 @@
|
|
|
109
109
|
"release": "release-it",
|
|
110
110
|
"test": "tsx --test **/__tests__/**/*.spec.ts",
|
|
111
111
|
"pretest:ci": "rm -rf coverage && mkdir -p coverage",
|
|
112
|
-
"test:ci": "glob-bin -c \"node --import tsx --test --no-warnings --experimental-test-coverage --test-reporter=cobertura --test-reporter-destination=coverage/cobertura-coverage.xml --test-reporter=spec --test-reporter-destination=stdout\" \"**/__tests__/**/*.spec.ts\""
|
|
112
|
+
"test:ci": "glob-bin -c \"node --import tsx --test --no-warnings --experimental-test-coverage --test-coverage-include='src/**' --test-coverage-exclude='**/__tests__/**' --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 --test-reporter=cobertura --test-reporter-destination=coverage/cobertura-coverage.xml --test-reporter=spec --test-reporter-destination=stdout\" \"**/__tests__/**/*.spec.ts\""
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
|
-
"@interstellar-tools/constants": "^1.
|
|
116
|
-
"@interstellar-tools/types": "^1.
|
|
115
|
+
"@interstellar-tools/constants": "^1.2.0",
|
|
116
|
+
"@interstellar-tools/types": "^1.6.0"
|
|
117
117
|
},
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@types/node": "^24.19.2",
|