@interstellar-tools/temporal 2.0.0 → 2.0.2
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/CHANGELOG.md +804 -0
- package/dist/convert-temporal-unit.d.ts +9 -8
- package/dist/convert-temporal-unit.d.ts.map +1 -1
- package/dist/convert-temporal-unit.js +39 -14
- package/dist/convert-temporal-unit.js.map +1 -1
- package/dist/normalize-temporal-unit.d.ts +2 -0
- package/dist/normalize-temporal-unit.d.ts.map +1 -1
- package/dist/normalize-temporal-unit.js +6 -1
- package/dist/normalize-temporal-unit.js.map +1 -1
- package/dist/time-scales.d.ts.map +1 -1
- package/dist/time-scales.js +4 -0
- package/dist/time-scales.js.map +1 -1
- package/package.json +6 -3
- package/src/convert-temporal-unit.ts +141 -0
- package/src/index.ts +7 -0
- package/src/mars-time.ts +204 -0
- package/src/normalize-temporal-unit.ts +142 -0
- package/src/time-scales.ts +291 -0
|
@@ -25,14 +25,14 @@ import type { TemporalInterface, TemporalUnitAliasType, TemporalUnitType } from
|
|
|
25
25
|
*/
|
|
26
26
|
export declare const SECONDS_PER: Readonly<Record<TemporalUnitType, number>>;
|
|
27
27
|
/**
|
|
28
|
-
* Convert a temporal **duration** between any two
|
|
28
|
+
* Convert a temporal **duration** between any two {@link TemporalUnitType} units or their aliases.
|
|
29
29
|
*
|
|
30
|
-
* -
|
|
30
|
+
* - Converts by the ratio of the units' lengths in {@link SECONDS_PER}, with
|
|
31
|
+
* the powers of ten kept apart, so whole numbers convert exactly: 1 ms is
|
|
32
|
+
* 1000 μs, not 1000.0000000000001.
|
|
31
33
|
* - Interprets `d` as the **SI day** and `yr/kyr/Myr/Gyr` via the **Julian year** convention.
|
|
32
|
-
* -
|
|
33
|
-
*
|
|
34
|
-
* - The `targetUnit` may be a canonical unit or an alias such as `'days'`; it is
|
|
35
|
-
* normalized to a canonical symbol.
|
|
34
|
+
* - Both `time.unit` and `targetUnit` may be canonical units or aliases such as
|
|
35
|
+
* `'days'`; they are normalized with `normalizeTemporalUnit`.
|
|
36
36
|
*
|
|
37
37
|
* $$
|
|
38
38
|
* \text{value}_{\text{target}}
|
|
@@ -41,7 +41,7 @@ export declare const SECONDS_PER: Readonly<Record<TemporalUnitType, number>>;
|
|
|
41
41
|
* {\mathrm{SECONDS\_PER}[u_{\text{out}}]}
|
|
42
42
|
* $$
|
|
43
43
|
*
|
|
44
|
-
* @param time Input duration `{ value, unit }
|
|
44
|
+
* @param time Input duration `{ value, unit }`, in a canonical unit or an alias.
|
|
45
45
|
* @param targetUnit Desired output unit, canonical or an alias (will be normalized).
|
|
46
46
|
* @returns A new `{ value, unit }` where `unit` is the canonical target symbol.
|
|
47
47
|
*
|
|
@@ -60,7 +60,8 @@ export declare const SECONDS_PER: Readonly<Record<TemporalUnitType, number>>;
|
|
|
60
60
|
* // → { value: 365.25, unit: 'd' }
|
|
61
61
|
* ```
|
|
62
62
|
*
|
|
63
|
-
* @throws {
|
|
63
|
+
* @throws {TypeError} If `time.unit` or `targetUnit` is not a string.
|
|
64
|
+
* @throws {RangeError} If `time.unit` or `targetUnit` is not a known unit or alias.
|
|
64
65
|
* @see SECONDS_PER_DAY
|
|
65
66
|
* @see JULIAN_YEAR_SECONDS
|
|
66
67
|
* @see normalizeTemporalUnit
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-temporal-unit.d.ts","sourceRoot":"","sources":["../src/convert-temporal-unit.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAInC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAuB/D,CAAC;
|
|
1
|
+
{"version":3,"file":"convert-temporal-unit.d.ts","sourceRoot":"","sources":["../src/convert-temporal-unit.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAInC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAuB/D,CAAC;AAuBL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,MAAM,iBAAiB,EACvB,YAAY,gBAAgB,GAAG,qBAAqB,KACnD,iBAaF,CAAC"}
|
|
@@ -45,15 +45,35 @@ export const SECONDS_PER = Object.freeze({
|
|
|
45
45
|
Myr: JULIAN_YEAR_SECONDS * 1e6,
|
|
46
46
|
Gyr: JULIAN_YEAR_SECONDS * 1e9
|
|
47
47
|
});
|
|
48
|
+
// Each unit as a whole number of seconds times a power of ten. 1e-3 and 1e-6
|
|
49
|
+
// aren't exact in binary, but 10 ** 3 is, so whole values can convert exactly
|
|
50
|
+
const SCALED = {
|
|
51
|
+
s: [1, 0],
|
|
52
|
+
ms: [1, -3],
|
|
53
|
+
μs: [1, -6],
|
|
54
|
+
ns: [1, -9],
|
|
55
|
+
ps: [1, -12],
|
|
56
|
+
fs: [1, -15],
|
|
57
|
+
as: [1, -18],
|
|
58
|
+
zs: [1, -21],
|
|
59
|
+
ys: [1, -24],
|
|
60
|
+
min: [60, 0],
|
|
61
|
+
h: [60 * 60, 0],
|
|
62
|
+
d: [SECONDS_PER_DAY, 0],
|
|
63
|
+
yr: [JULIAN_YEAR_SECONDS, 0],
|
|
64
|
+
kyr: [JULIAN_YEAR_SECONDS, 3],
|
|
65
|
+
Myr: [JULIAN_YEAR_SECONDS, 6],
|
|
66
|
+
Gyr: [JULIAN_YEAR_SECONDS, 9]
|
|
67
|
+
};
|
|
48
68
|
/**
|
|
49
|
-
* Convert a temporal **duration** between any two
|
|
69
|
+
* Convert a temporal **duration** between any two {@link TemporalUnitType} units or their aliases.
|
|
50
70
|
*
|
|
51
|
-
* -
|
|
71
|
+
* - Converts by the ratio of the units' lengths in {@link SECONDS_PER}, with
|
|
72
|
+
* the powers of ten kept apart, so whole numbers convert exactly: 1 ms is
|
|
73
|
+
* 1000 μs, not 1000.0000000000001.
|
|
52
74
|
* - Interprets `d` as the **SI day** and `yr/kyr/Myr/Gyr` via the **Julian year** convention.
|
|
53
|
-
* -
|
|
54
|
-
*
|
|
55
|
-
* - The `targetUnit` may be a canonical unit or an alias such as `'days'`; it is
|
|
56
|
-
* normalized to a canonical symbol.
|
|
75
|
+
* - Both `time.unit` and `targetUnit` may be canonical units or aliases such as
|
|
76
|
+
* `'days'`; they are normalized with `normalizeTemporalUnit`.
|
|
57
77
|
*
|
|
58
78
|
* $$
|
|
59
79
|
* \text{value}_{\text{target}}
|
|
@@ -62,7 +82,7 @@ export const SECONDS_PER = Object.freeze({
|
|
|
62
82
|
* {\mathrm{SECONDS\_PER}[u_{\text{out}}]}
|
|
63
83
|
* $$
|
|
64
84
|
*
|
|
65
|
-
* @param time Input duration `{ value, unit }
|
|
85
|
+
* @param time Input duration `{ value, unit }`, in a canonical unit or an alias.
|
|
66
86
|
* @param targetUnit Desired output unit, canonical or an alias (will be normalized).
|
|
67
87
|
* @returns A new `{ value, unit }` where `unit` is the canonical target symbol.
|
|
68
88
|
*
|
|
@@ -81,18 +101,23 @@ export const SECONDS_PER = Object.freeze({
|
|
|
81
101
|
* // → { value: 365.25, unit: 'd' }
|
|
82
102
|
* ```
|
|
83
103
|
*
|
|
84
|
-
* @throws {
|
|
104
|
+
* @throws {TypeError} If `time.unit` or `targetUnit` is not a string.
|
|
105
|
+
* @throws {RangeError} If `time.unit` or `targetUnit` is not a known unit or alias.
|
|
85
106
|
* @see SECONDS_PER_DAY
|
|
86
107
|
* @see JULIAN_YEAR_SECONDS
|
|
87
108
|
* @see normalizeTemporalUnit
|
|
88
109
|
*/
|
|
89
110
|
export const convertTemporalUnit = (time, targetUnit) => {
|
|
90
111
|
const normalizedTargetUnit = normalizeTemporalUnit(targetUnit);
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
//
|
|
95
|
-
const
|
|
96
|
-
|
|
112
|
+
const [secondsIn, powerIn] = SCALED[normalizeTemporalUnit(time.unit)];
|
|
113
|
+
const [secondsOut, powerOut] = SCALED[normalizedTargetUnit];
|
|
114
|
+
const power = powerIn - powerOut;
|
|
115
|
+
// Whole numbers on both sides, so a single division does the rounding
|
|
116
|
+
const numerator = secondsIn * 10 ** Math.max(power, 0);
|
|
117
|
+
const denominator = secondsOut * 10 ** Math.max(-power, 0);
|
|
118
|
+
return {
|
|
119
|
+
value: (time.value * numerator) / denominator,
|
|
120
|
+
unit: normalizedTargetUnit
|
|
121
|
+
};
|
|
97
122
|
};
|
|
98
123
|
//# sourceMappingURL=convert-temporal-unit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-temporal-unit.js","sourceRoot":"","sources":["../src/convert-temporal-unit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,eAAe,EAChB,MAAM,+BAA+B,CAAC;AAOvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,MAAM,CAAC,MAAM,CAAC;IACZ,yBAAyB;IACzB,CAAC,EAAE,CAAC;IACJ,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IAET,0BAA0B;IAC1B,GAAG,EAAE,EAAE;IACP,CAAC,EAAE,EAAE,GAAG,EAAE;IACV,CAAC,EAAE,eAAe;IAElB,kCAAkC;IAClC,EAAE,EAAE,mBAAm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I,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAE3D,OAAO;QACL,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,WAAW;QAC7C,IAAI,EAAE,oBAAoB;KAC3B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -85,10 +85,12 @@ export declare const NORMALIZE_TEMPORAL_UNIT: Readonly<{
|
|
|
85
85
|
* - **Case-sensitive** exact match against {@link NORMALIZE_TEMPORAL_UNIT}. For example, `"Seconds"` (capital S)
|
|
86
86
|
* will fail; use `"seconds"` instead, or pre-normalize casing upstream if desired.
|
|
87
87
|
* - The ASCII alias `"us"` is accepted and normalized to the Unicode microsecond symbol `"μs"`.
|
|
88
|
+
* - The input is NFKC-normalized, so the micro sign `"µs"` (U+00B5, as keyboards type it) is read as `"μs"` (U+03BC).
|
|
88
89
|
*
|
|
89
90
|
* @param u - The input unit string. Leading/trailing whitespace is ignored; content is **case-sensitive**.
|
|
90
91
|
* @returns The canonical {@link TemporalUnitType} (e.g., `"s"`, `"ms"`, `"μs"`, `"min"`, `"h"`, `"d"`, `"yr"`, `"kyr"`, `"Myr"`, `"Gyr"`).
|
|
91
92
|
*
|
|
93
|
+
* @throws {TypeError} If `u` is not a string.
|
|
92
94
|
* @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError | RangeError} If `u` does not match any known key in {@link NORMALIZE_TEMPORAL_UNIT}.
|
|
93
95
|
*
|
|
94
96
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-temporal-unit.d.ts","sourceRoot":"","sources":["../src/normalize-temporal-unit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAGnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDlC,CAAC;AAGH
|
|
1
|
+
{"version":3,"file":"normalize-temporal-unit.d.ts","sourceRoot":"","sources":["../src/normalize-temporal-unit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAGnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDlC,CAAC;AAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,eAAO,MAAM,qBAAqB,GAAI,GAAG,MAAM,KAAG,gBAajD,CAAC"}
|
|
@@ -89,10 +89,12 @@ export const NORMALIZE_TEMPORAL_UNIT = Object.freeze({
|
|
|
89
89
|
* - **Case-sensitive** exact match against {@link NORMALIZE_TEMPORAL_UNIT}. For example, `"Seconds"` (capital S)
|
|
90
90
|
* will fail; use `"seconds"` instead, or pre-normalize casing upstream if desired.
|
|
91
91
|
* - The ASCII alias `"us"` is accepted and normalized to the Unicode microsecond symbol `"μs"`.
|
|
92
|
+
* - The input is NFKC-normalized, so the micro sign `"µs"` (U+00B5, as keyboards type it) is read as `"μs"` (U+03BC).
|
|
92
93
|
*
|
|
93
94
|
* @param u - The input unit string. Leading/trailing whitespace is ignored; content is **case-sensitive**.
|
|
94
95
|
* @returns The canonical {@link TemporalUnitType} (e.g., `"s"`, `"ms"`, `"μs"`, `"min"`, `"h"`, `"d"`, `"yr"`, `"kyr"`, `"Myr"`, `"Gyr"`).
|
|
95
96
|
*
|
|
97
|
+
* @throws {TypeError} If `u` is not a string.
|
|
96
98
|
* @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError | RangeError} If `u` does not match any known key in {@link NORMALIZE_TEMPORAL_UNIT}.
|
|
97
99
|
*
|
|
98
100
|
* @example
|
|
@@ -114,7 +116,10 @@ export const NORMALIZE_TEMPORAL_UNIT = Object.freeze({
|
|
|
114
116
|
*/
|
|
115
117
|
/* node:coverage enable */
|
|
116
118
|
export const normalizeTemporalUnit = (u) => {
|
|
117
|
-
|
|
119
|
+
if (typeof u !== 'string')
|
|
120
|
+
throw new TypeError(`unit must be a string. Received: ${String(u)}`);
|
|
121
|
+
// NFKC turns the micro sign, U+00B5, into the Greek mu the table uses
|
|
122
|
+
const k = u.trim().normalize('NFKC');
|
|
118
123
|
const v = Object.prototype.hasOwnProperty.call(NORMALIZE_TEMPORAL_UNIT, k)
|
|
119
124
|
? NORMALIZE_TEMPORAL_UNIT[k]
|
|
120
125
|
: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-temporal-unit.js","sourceRoot":"","sources":["../src/normalize-temporal-unit.ts"],"names":[],"mappings":"AAKA,2BAA2B;AAC3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,0BAA0B;AAC1B,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC;IACnD,uCAAuC;IACvC,CAAC,EAAE,GAAG;IACN,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IAEV,sBAAsB;IACtB,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,GAAG;IACZ,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,EAAE,EAAE,IAAI;IACR,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,GAAG;IACV,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,GAAG,EAAE,IAAI;IAET,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,UAAU,EAAE,KAAK;IACjB,EAAE,EAAE,KAAK;IACT,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,UAAU,EAAE,KAAK;IACjB,EAAE,EAAE,KAAK;CAIV,CAAC,CAAC;AAEH,2BAA2B;AAC3B
|
|
1
|
+
{"version":3,"file":"normalize-temporal-unit.js","sourceRoot":"","sources":["../src/normalize-temporal-unit.ts"],"names":[],"mappings":"AAKA,2BAA2B;AAC3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,0BAA0B;AAC1B,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC;IACnD,uCAAuC;IACvC,CAAC,EAAE,GAAG;IACN,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IAEV,sBAAsB;IACtB,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,GAAG;IACZ,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB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C;AACX,CAAC,CAAC"}
|
|
@@ -1 +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;AAgF/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,MACR,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;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,
|
|
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;AAgF/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,MACR,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;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,IA6CF,CAAC"}
|
package/dist/time-scales.js
CHANGED
|
@@ -206,6 +206,10 @@ export const dateFromJulianDate = (jd, scale = 'UTC') => {
|
|
|
206
206
|
// Milliseconds since 1970-01-01T00:00:00 on the scale's clock, TT for TDB
|
|
207
207
|
const exact = (jd - JULIAN_DATE_UNIX_EPOCH) * MILLISECONDS_PER_DAY;
|
|
208
208
|
const onScale = Math.round(scale === 'TDB' ? exact - tdbMinusTt(exact) : exact);
|
|
209
|
+
// Further back than a Date reaches: say so here, as the leap-second check
|
|
210
|
+
// below can't print a date that far back
|
|
211
|
+
if (onScale < -8.64e15)
|
|
212
|
+
throw new RangeError(`jd is outside the range of a Date. Received: ${jd}`);
|
|
209
213
|
let ms = onScale;
|
|
210
214
|
if (scale !== 'UTC' && scale !== 'UT1') {
|
|
211
215
|
// Back to TAI, then to UTC. The leap seconds depend on the UTC moment:
|
package/dist/time-scales.js.map
CHANGED
|
@@ -1 +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;IACvC,KAAK;IACL,KAAK;IACL,IAAI;IACJ,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC;AACF,0EAA0E;AAC1E,8BAA8B;AAC9B,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,yBAAyB;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Aa,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": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
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",
|
|
@@ -100,7 +100,10 @@
|
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
"files": [
|
|
103
|
-
"dist"
|
|
103
|
+
"dist",
|
|
104
|
+
"src",
|
|
105
|
+
"!src/**/__tests__",
|
|
106
|
+
"CHANGELOG.md"
|
|
104
107
|
],
|
|
105
108
|
"sideEffects": false,
|
|
106
109
|
"scripts": {
|
|
@@ -118,7 +121,7 @@
|
|
|
118
121
|
"devDependencies": {
|
|
119
122
|
"@types/node": "^24.19.2",
|
|
120
123
|
"fast-check": "4.10.2",
|
|
121
|
-
"prettier": "^3.
|
|
124
|
+
"prettier": "^3.10.1",
|
|
122
125
|
"typescript": "^6.0.3"
|
|
123
126
|
},
|
|
124
127
|
"engines": {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JULIAN_YEAR_SECONDS,
|
|
3
|
+
SECONDS_PER_DAY
|
|
4
|
+
} from '@interstellar-tools/constants';
|
|
5
|
+
import type {
|
|
6
|
+
TemporalInterface,
|
|
7
|
+
TemporalUnitAliasType,
|
|
8
|
+
TemporalUnitType
|
|
9
|
+
} from '@interstellar-tools/types';
|
|
10
|
+
|
|
11
|
+
import { normalizeTemporalUnit } from './normalize-temporal-unit.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Seconds-per-unit lookup for all canonical {@link TemporalUnitType} symbols.
|
|
15
|
+
*
|
|
16
|
+
* ### Conventions
|
|
17
|
+
* - **Base**: conversions are performed via **seconds**.
|
|
18
|
+
* - **SI day**: `d = 86 400 s` (from {@link SECONDS_PER_DAY}).
|
|
19
|
+
* - **Julian year**: `yr = 365.25 d = 31 557 600 s`
|
|
20
|
+
* (from {@link JULIAN_YEAR_SECONDS}); `kyr/Myr/Gyr` are powers of 10 thereof.
|
|
21
|
+
* - Units are **canonical** and **case-sensitive** (e.g., `'μs'` uses the Unicode micro sign).
|
|
22
|
+
* - The table is frozen: it can be read, but not changed at runtime.
|
|
23
|
+
*
|
|
24
|
+
* $$
|
|
25
|
+
* \text{seconds}(u) \;=\; \text{value}\times \mathrm{SECONDS\_PER}[u]
|
|
26
|
+
* $$
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // seconds per hour:
|
|
31
|
+
* SECONDS_PER.h; // 3600
|
|
32
|
+
*
|
|
33
|
+
* // seconds in a Julian year:
|
|
34
|
+
* SECONDS_PER.yr; // 31_557_600
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export const SECONDS_PER: Readonly<Record<TemporalUnitType, number>> =
|
|
38
|
+
Object.freeze({
|
|
39
|
+
// SI base & submultiples
|
|
40
|
+
s: 1,
|
|
41
|
+
ms: 1e-3,
|
|
42
|
+
μs: 1e-6,
|
|
43
|
+
ns: 1e-9,
|
|
44
|
+
ps: 1e-12,
|
|
45
|
+
fs: 1e-15,
|
|
46
|
+
as: 1e-18,
|
|
47
|
+
zs: 1e-21,
|
|
48
|
+
ys: 1e-24,
|
|
49
|
+
|
|
50
|
+
// convenient larger units
|
|
51
|
+
min: 60,
|
|
52
|
+
h: 60 * 60,
|
|
53
|
+
d: SECONDS_PER_DAY,
|
|
54
|
+
|
|
55
|
+
// year family (Julian-year-based)
|
|
56
|
+
yr: JULIAN_YEAR_SECONDS,
|
|
57
|
+
kyr: JULIAN_YEAR_SECONDS * 1e3,
|
|
58
|
+
Myr: JULIAN_YEAR_SECONDS * 1e6,
|
|
59
|
+
Gyr: JULIAN_YEAR_SECONDS * 1e9
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Each unit as a whole number of seconds times a power of ten. 1e-3 and 1e-6
|
|
63
|
+
// aren't exact in binary, but 10 ** 3 is, so whole values can convert exactly
|
|
64
|
+
const SCALED: Readonly<Record<TemporalUnitType, readonly [number, number]>> = {
|
|
65
|
+
s: [1, 0],
|
|
66
|
+
ms: [1, -3],
|
|
67
|
+
μs: [1, -6],
|
|
68
|
+
ns: [1, -9],
|
|
69
|
+
ps: [1, -12],
|
|
70
|
+
fs: [1, -15],
|
|
71
|
+
as: [1, -18],
|
|
72
|
+
zs: [1, -21],
|
|
73
|
+
ys: [1, -24],
|
|
74
|
+
min: [60, 0],
|
|
75
|
+
h: [60 * 60, 0],
|
|
76
|
+
d: [SECONDS_PER_DAY, 0],
|
|
77
|
+
yr: [JULIAN_YEAR_SECONDS, 0],
|
|
78
|
+
kyr: [JULIAN_YEAR_SECONDS, 3],
|
|
79
|
+
Myr: [JULIAN_YEAR_SECONDS, 6],
|
|
80
|
+
Gyr: [JULIAN_YEAR_SECONDS, 9]
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Convert a temporal **duration** between any two {@link TemporalUnitType} units or their aliases.
|
|
85
|
+
*
|
|
86
|
+
* - Converts by the ratio of the units' lengths in {@link SECONDS_PER}, with
|
|
87
|
+
* the powers of ten kept apart, so whole numbers convert exactly: 1 ms is
|
|
88
|
+
* 1000 μs, not 1000.0000000000001.
|
|
89
|
+
* - Interprets `d` as the **SI day** and `yr/kyr/Myr/Gyr` via the **Julian year** convention.
|
|
90
|
+
* - Both `time.unit` and `targetUnit` may be canonical units or aliases such as
|
|
91
|
+
* `'days'`; they are normalized with `normalizeTemporalUnit`.
|
|
92
|
+
*
|
|
93
|
+
* $$
|
|
94
|
+
* \text{value}_{\text{target}}
|
|
95
|
+
* \;=\;
|
|
96
|
+
* \frac{\text{value}_{\text{in}} \cdot \mathrm{SECONDS\_PER}[u_{\text{in}}]}
|
|
97
|
+
* {\mathrm{SECONDS\_PER}[u_{\text{out}}]}
|
|
98
|
+
* $$
|
|
99
|
+
*
|
|
100
|
+
* @param time Input duration `{ value, unit }`, in a canonical unit or an alias.
|
|
101
|
+
* @param targetUnit Desired output unit, canonical or an alias (will be normalized).
|
|
102
|
+
* @returns A new `{ value, unit }` where `unit` is the canonical target symbol.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* convertTemporalUnit({ value: 2, unit: 'h' }, 'min');
|
|
107
|
+
* // → { value: 120, unit: 'min' }
|
|
108
|
+
*
|
|
109
|
+
* convertTemporalUnit({ value: 1, unit: 'd' }, 's');
|
|
110
|
+
* // → { value: 86_400, unit: 's' }
|
|
111
|
+
*
|
|
112
|
+
* convertTemporalUnit({ value: 3, unit: 'Myr' }, 'kyr');
|
|
113
|
+
* // → { value: 3000, unit: 'kyr' }
|
|
114
|
+
*
|
|
115
|
+
* convertTemporalUnit({ value: 1, unit: 'yr' }, 'd');
|
|
116
|
+
* // → { value: 365.25, unit: 'd' }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @throws {TypeError} If `time.unit` or `targetUnit` is not a string.
|
|
120
|
+
* @throws {RangeError} If `time.unit` or `targetUnit` is not a known unit or alias.
|
|
121
|
+
* @see SECONDS_PER_DAY
|
|
122
|
+
* @see JULIAN_YEAR_SECONDS
|
|
123
|
+
* @see normalizeTemporalUnit
|
|
124
|
+
*/
|
|
125
|
+
export const convertTemporalUnit = (
|
|
126
|
+
time: TemporalInterface,
|
|
127
|
+
targetUnit: TemporalUnitType | TemporalUnitAliasType
|
|
128
|
+
): TemporalInterface => {
|
|
129
|
+
const normalizedTargetUnit = normalizeTemporalUnit(targetUnit);
|
|
130
|
+
const [secondsIn, powerIn] = SCALED[normalizeTemporalUnit(time.unit)];
|
|
131
|
+
const [secondsOut, powerOut] = SCALED[normalizedTargetUnit];
|
|
132
|
+
const power = powerIn - powerOut;
|
|
133
|
+
// Whole numbers on both sides, so a single division does the rounding
|
|
134
|
+
const numerator = secondsIn * 10 ** Math.max(power, 0);
|
|
135
|
+
const denominator = secondsOut * 10 ** Math.max(-power, 0);
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
value: (time.value * numerator) / denominator,
|
|
139
|
+
unit: normalizedTargetUnit
|
|
140
|
+
};
|
|
141
|
+
};
|
package/src/index.ts
ADDED
package/src/mars-time.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { MARS_SOL_DAYS } from '@interstellar-tools/constants';
|
|
2
|
+
import type { Radians } from '@interstellar-tools/types';
|
|
3
|
+
|
|
4
|
+
import { julianDate } from './time-scales.js';
|
|
5
|
+
|
|
6
|
+
// Mars24's reference: MSD 44 796.0 − 0.0009626 at JD 2451549.5 TT, the start
|
|
7
|
+
// of 6 January 2000 on Earth
|
|
8
|
+
const MSD_REFERENCE_JD_TT = 2_451_549.5;
|
|
9
|
+
const MSD_AT_REFERENCE = 44_796 - 0.000_962_6;
|
|
10
|
+
const TWO_PI = 2 * Math.PI;
|
|
11
|
+
const fraction = (x: number) => x - Math.floor(x);
|
|
12
|
+
const assertLongitude = (longitude: number) => {
|
|
13
|
+
if (!Number.isFinite(longitude))
|
|
14
|
+
throw new TypeError(
|
|
15
|
+
`longitude must be a finite number. Received: ${longitude}`
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The **Mars Sol Date** of a moment: a continuous count of sols, Mars's mean
|
|
21
|
+
* solar days, like the Julian date for Earth.
|
|
22
|
+
*
|
|
23
|
+
* $$
|
|
24
|
+
* \mathrm{MSD} = \frac{\mathrm{JD_{TT}} - 2\,451\,549.5}{1.0274912517} + 44\,796.0 - 0.0009626
|
|
25
|
+
* $$
|
|
26
|
+
*
|
|
27
|
+
* Where:
|
|
28
|
+
* - $ \mathrm{JD_{TT}} $ is the Julian date in Terrestrial Time (days)
|
|
29
|
+
* - $ 1.0274912517 $ is the sol in Earth days, {@link "@interstellar-tools/constants"!MARS_SOL_DAYS | MARS_SOL_DAYS}
|
|
30
|
+
*
|
|
31
|
+
* ::: info Notes
|
|
32
|
+
*
|
|
33
|
+
* - The count starts on 29 December 1873, at about noon in Greenwich.
|
|
34
|
+
* - Each new sol begins at mean midnight at Airy-0, when
|
|
35
|
+
* {@link coordinatedMarsTime} wraps to 0.
|
|
36
|
+
* - From NASA GISS's Mars24 algorithm, refined from Allison & McEwen (2000).
|
|
37
|
+
*
|
|
38
|
+
* :::
|
|
39
|
+
*
|
|
40
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01).
|
|
41
|
+
* @returns The Mars Sol Date in **sols**.
|
|
42
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
43
|
+
* @throws {RangeError} If `date` is before 1972-01-01, where TT isn't defined from the leap seconds.
|
|
44
|
+
* @group Mars time
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* marsSolDate(new Date('2000-01-06T00:00:00Z')); // ≈ 44 795.99976
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @see {@link coordinatedMarsTime}
|
|
52
|
+
* @see https://www.giss.nasa.gov/tools/mars24/help/algorithm.html Mars24 algorithm
|
|
53
|
+
*/
|
|
54
|
+
export const marsSolDate = (date: Date): number =>
|
|
55
|
+
(julianDate(date, 'TT') - MSD_REFERENCE_JD_TT) / MARS_SOL_DAYS +
|
|
56
|
+
MSD_AT_REFERENCE;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* **Coordinated Mars Time** (MTC): the mean solar time at Mars's prime
|
|
60
|
+
* meridian, Airy-0, in hours, like UTC is at Greenwich.
|
|
61
|
+
*
|
|
62
|
+
* $$
|
|
63
|
+
* \mathrm{MTC} = 24 \times (\mathrm{MSD} \bmod 1)
|
|
64
|
+
* $$
|
|
65
|
+
*
|
|
66
|
+
* ::: info Notes
|
|
67
|
+
*
|
|
68
|
+
* - A Mars hour is a 24th of a sol: 1 h 1 m 39 s of Earth time.
|
|
69
|
+
* - It's mean time: the real Sun can be up to about 50 minutes ahead of or behind it,
|
|
70
|
+
* because of Mars's eccentric orbit and tilt, the equation of time.
|
|
71
|
+
*
|
|
72
|
+
* :::
|
|
73
|
+
*
|
|
74
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01).
|
|
75
|
+
* @returns The time at Airy-0 in **Mars hours**, from 0 up to 24.
|
|
76
|
+
* @throws {TypeError} If `date` is not a valid `Date`.
|
|
77
|
+
* @throws {RangeError} If `date` is before 1972-01-01.
|
|
78
|
+
* @group Mars time
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* // Mars24's first worked example: 23:59:39 at Airy-0
|
|
83
|
+
* coordinatedMarsTime(new Date('2000-01-06T00:00:00Z')); // ≈ 23.99425 h
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @see {@link marsSolDate}
|
|
87
|
+
* @see {@link marsLocalMeanSolarTime}
|
|
88
|
+
*/
|
|
89
|
+
export const coordinatedMarsTime = (date: Date): number =>
|
|
90
|
+
24 * fraction(marsSolDate(date));
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The **local mean solar time on Mars** at a longitude, in hours: Coordinated
|
|
94
|
+
* Mars Time plus the east longitude in hours, 15° to the hour.
|
|
95
|
+
*
|
|
96
|
+
* $$
|
|
97
|
+
* \mathrm{LMST} = \left( \mathrm{MTC} + \lambda \, \frac{24\ \mathrm{h}}{2\pi} \right) \bmod 24\ \mathrm{h}
|
|
98
|
+
* $$
|
|
99
|
+
*
|
|
100
|
+
* Where:
|
|
101
|
+
* - $ \lambda $ is the planetocentric east longitude (rad)
|
|
102
|
+
*
|
|
103
|
+
* ::: info Notes
|
|
104
|
+
*
|
|
105
|
+
* - **East longitude**, as the IAU gives it for Mars. Mars24 counts west
|
|
106
|
+
* longitude, so 184.702° W there is 175.298° E here.
|
|
107
|
+
* - It's mean time, by a Sun that moves evenly. The real Sun can be up to about
|
|
108
|
+
* 50 minutes ahead of or behind it.
|
|
109
|
+
*
|
|
110
|
+
* :::
|
|
111
|
+
*
|
|
112
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01).
|
|
113
|
+
* @param longitude - The east longitude in **radians** (finite; any turn).
|
|
114
|
+
* @returns The local mean solar time in **Mars hours**, from 0 up to 24.
|
|
115
|
+
* @throws {TypeError} If `date` is not a valid `Date`, or `longitude` is not a finite number.
|
|
116
|
+
* @throws {RangeError} If `date` is before 1972-01-01.
|
|
117
|
+
* @group Mars time
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const DEG = Math.PI / 180;
|
|
122
|
+
*
|
|
123
|
+
* // Spirit's site, at local midnight on Earth's clock: 00:51 mean time
|
|
124
|
+
* marsLocalMeanSolarTime(
|
|
125
|
+
* new Date('2004-01-03T13:46:31Z'),
|
|
126
|
+
* (175.298 * DEG) as Radians
|
|
127
|
+
* ); // ≈ 0.8519 h
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @see {@link coordinatedMarsTime}
|
|
131
|
+
* @see {@link missionSol}
|
|
132
|
+
*/
|
|
133
|
+
export const marsLocalMeanSolarTime = (
|
|
134
|
+
date: Date,
|
|
135
|
+
longitude: Radians
|
|
136
|
+
): number => {
|
|
137
|
+
assertLongitude(longitude);
|
|
138
|
+
|
|
139
|
+
return 24 * fraction(marsSolDate(date) + longitude / TWO_PI);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The **mission sol** at a landing site: the number of the sol a rover is on,
|
|
144
|
+
* counted from its landing.
|
|
145
|
+
*
|
|
146
|
+
* $$
|
|
147
|
+
* \text{sol} = s_0 + \lfloor \mathrm{MSD} + \lambda / 2\pi \rfloor - \lfloor \mathrm{MSD_{landing}} + \lambda / 2\pi \rfloor
|
|
148
|
+
* $$
|
|
149
|
+
*
|
|
150
|
+
* Where:
|
|
151
|
+
* - $ s_0 $ is the number of the landing sol
|
|
152
|
+
* - $ \lambda $ is the east longitude of the mission's clock (rad)
|
|
153
|
+
*
|
|
154
|
+
* ::: info Notes
|
|
155
|
+
*
|
|
156
|
+
* - A new sol begins at local mean midnight at the site.
|
|
157
|
+
* - **Sol 0 or sol 1?** Curiosity and Perseverance call their landing sol 0.
|
|
158
|
+
* Spirit and Opportunity called it sol 1.
|
|
159
|
+
* - Before landing, the count goes below the landing sol.
|
|
160
|
+
* - Spirit and Opportunity ran on a hybrid of true solar time, a few minutes
|
|
161
|
+
* off mean time: close to their midnights, their count can differ by one.
|
|
162
|
+
*
|
|
163
|
+
* :::
|
|
164
|
+
*
|
|
165
|
+
* @param date - The moment, as a UTC `Date` (on or after 1972-01-01).
|
|
166
|
+
* @param landingDate - The moment of landing, as a UTC `Date` (on or after 1972-01-01).
|
|
167
|
+
* @param longitude - The east longitude of the mission's clock in **radians** (finite).
|
|
168
|
+
* @param firstSol - The number of the landing sol: 0 or 1 (an integer). Defaults to 0.
|
|
169
|
+
* @returns The sol number, an integer.
|
|
170
|
+
* @throws {TypeError} If a date is not a valid `Date`, `longitude` is not a finite number, or `firstSol` is not an integer.
|
|
171
|
+
* @throws {RangeError} If a date is before 1972-01-01.
|
|
172
|
+
* @group Mars time
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const DEG = Math.PI / 180;
|
|
177
|
+
*
|
|
178
|
+
* // Curiosity landed in Gale crater, its clock at 137.42° E
|
|
179
|
+
* missionSol(
|
|
180
|
+
* new Date('2015-05-30T12:00:00Z'),
|
|
181
|
+
* new Date('2012-08-06T05:17:57Z'),
|
|
182
|
+
* (137.42 * DEG) as Radians
|
|
183
|
+
* ); // 1000
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @see {@link marsLocalMeanSolarTime}
|
|
187
|
+
* @see https://www.giss.nasa.gov/tools/mars24/help/notes.html Mars24 technical notes, on mission sols
|
|
188
|
+
*/
|
|
189
|
+
export const missionSol = (
|
|
190
|
+
date: Date,
|
|
191
|
+
landingDate: Date,
|
|
192
|
+
longitude: Radians,
|
|
193
|
+
firstSol = 0
|
|
194
|
+
): number => {
|
|
195
|
+
assertLongitude(longitude);
|
|
196
|
+
|
|
197
|
+
if (!Number.isInteger(firstSol))
|
|
198
|
+
throw new TypeError(`firstSol must be an integer. Received: ${firstSol}`);
|
|
199
|
+
|
|
200
|
+
const local = (moment: Date) =>
|
|
201
|
+
Math.floor(marsSolDate(moment) + longitude / TWO_PI);
|
|
202
|
+
|
|
203
|
+
return firstSol + local(date) - local(landingDate);
|
|
204
|
+
};
|