gnss-js 0.1.0 → 0.1.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/dist/{index.mjs → index.cjs} +259 -115
- package/dist/{index.d.mts → index.d.cts} +20 -15
- package/dist/index.d.ts +20 -15
- package/dist/index.js +159 -216
- package/jest.config.ts +9 -0
- package/package.json +4 -2
- package/test/functions.test.ts +63 -0
- package/test/gnss-scales.test.ts +95 -0
- package/test/julian.test.ts +145 -0
- package/test/rinex.test.ts +11 -0
- package/test/test.ts +10 -0
- package/test/utc.test.ts +25 -0
- package/jest.config.js +0 -6
- package/test/functions.test.js +0 -69
- package/test/gnss-scales.test.js +0 -78
- package/test/julian.test.js +0 -41
- package/test/rinex.test.js +0 -11
- package/test/utc.test.js +0 -19
|
@@ -1,3 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DAYS_MJD2000_MJD: () => DAYS_MJD2000_MJD,
|
|
24
|
+
DAYS_MJD_JULIAN: () => DAYS_MJD_JULIAN,
|
|
25
|
+
MILLISECONDS_GPS_TAI: () => MILLISECONDS_GPS_TAI,
|
|
26
|
+
MILLISECONDS_IN_DAY: () => MILLISECONDS_IN_DAY,
|
|
27
|
+
MILLISECONDS_IN_HOUR: () => MILLISECONDS_IN_HOUR,
|
|
28
|
+
MILLISECONDS_IN_MINUTE: () => MILLISECONDS_IN_MINUTE,
|
|
29
|
+
MILLISECONDS_IN_SECOND: () => MILLISECONDS_IN_SECOND,
|
|
30
|
+
MILLISECONDS_IN_WEEK: () => MILLISECONDS_IN_WEEK,
|
|
31
|
+
MILLISECONDS_TT_TAI: () => MILLISECONDS_TT_TAI,
|
|
32
|
+
RINEX_CODES: () => RINEX_CODES,
|
|
33
|
+
SECONDS_IN_DAY: () => SECONDS_IN_DAY,
|
|
34
|
+
SECONDS_IN_HOUR: () => SECONDS_IN_HOUR,
|
|
35
|
+
SECONDS_IN_MINUTE: () => SECONDS_IN_MINUTE,
|
|
36
|
+
SECONDS_IN_WEEK: () => SECONDS_IN_WEEK,
|
|
37
|
+
START_BDS_TIME: () => START_BDS_TIME,
|
|
38
|
+
START_GAL_TIME: () => START_GAL_TIME,
|
|
39
|
+
START_GLO_LEAP: () => START_GLO_LEAP,
|
|
40
|
+
START_GPS_TIME: () => START_GPS_TIME,
|
|
41
|
+
START_JULIAN_TAI: () => START_JULIAN_TAI,
|
|
42
|
+
START_MJD_UNIX_SECONDS: () => START_MJD_UNIX_SECONDS,
|
|
43
|
+
START_NTP_TIME: () => START_NTP_TIME,
|
|
44
|
+
START_TAI_TIME: () => START_TAI_TIME,
|
|
45
|
+
START_UNIX_TIME: () => START_UNIX_TIME,
|
|
46
|
+
Scale: () => Scale,
|
|
47
|
+
getBdsTime: () => getBdsTime,
|
|
48
|
+
getDateFromBdsTime: () => getDateFromBdsTime,
|
|
49
|
+
getDateFromDayOfWeek: () => getDateFromDayOfWeek,
|
|
50
|
+
getDateFromDayOfYear: () => getDateFromDayOfYear,
|
|
51
|
+
getDateFromGalTime: () => getDateFromGalTime,
|
|
52
|
+
getDateFromGloN: () => getDateFromGloN,
|
|
53
|
+
getDateFromGpsData: () => getDateFromGpsData,
|
|
54
|
+
getDateFromGpsTime: () => getDateFromGpsTime,
|
|
55
|
+
getDateFromHourCode: () => getDateFromHourCode,
|
|
56
|
+
getDateFromJulianDate: () => getDateFromJulianDate,
|
|
57
|
+
getDateFromMJD: () => getDateFromMJD,
|
|
58
|
+
getDateFromMJD2000: () => getDateFromMJD2000,
|
|
59
|
+
getDateFromRINEX: () => getDateFromRINEX,
|
|
60
|
+
getDateFromTai: () => getDateFromTai,
|
|
61
|
+
getDateFromTimeOfDay: () => getDateFromTimeOfDay,
|
|
62
|
+
getDateFromTt: () => getDateFromTt,
|
|
63
|
+
getDateFromUnixTime: () => getDateFromUnixTime,
|
|
64
|
+
getDateFromUtc: () => getDateFromUtc,
|
|
65
|
+
getDayOfWeek: () => getDayOfWeek,
|
|
66
|
+
getDayOfYear: () => getDayOfYear,
|
|
67
|
+
getGalTime: () => getGalTime,
|
|
68
|
+
getGloN4: () => getGloN4,
|
|
69
|
+
getGloNA: () => getGloNA,
|
|
70
|
+
getGpsLeap: () => getGpsLeap,
|
|
71
|
+
getGpsTime: () => getGpsTime,
|
|
72
|
+
getHourCode: () => getHourCode,
|
|
73
|
+
getHoursFromTimeDifference: () => getHoursFromTimeDifference,
|
|
74
|
+
getJulianDate: () => getJulianDate,
|
|
75
|
+
getLeap: () => getLeap,
|
|
76
|
+
getMJD: () => getMJD,
|
|
77
|
+
getMJD2000: () => getMJD2000,
|
|
78
|
+
getMinutesFromTimeDifference: () => getMinutesFromTimeDifference,
|
|
79
|
+
getNtpTime: () => getNtpTime,
|
|
80
|
+
getRINEX: () => getRINEX,
|
|
81
|
+
getSecondsFromTimeDifference: () => getSecondsFromTimeDifference,
|
|
82
|
+
getTaiDate: () => getTaiDate,
|
|
83
|
+
getTimeDifference: () => getTimeDifference,
|
|
84
|
+
getTimeDifferenceFromDays: () => getTimeDifferenceFromDays,
|
|
85
|
+
getTimeDifferenceFromHours: () => getTimeDifferenceFromHours,
|
|
86
|
+
getTimeDifferenceFromMinutes: () => getTimeDifferenceFromMinutes,
|
|
87
|
+
getTimeDifferenceFromObject: () => getTimeDifferenceFromObject,
|
|
88
|
+
getTimeDifferenceFromSeconds: () => getTimeDifferenceFromSeconds,
|
|
89
|
+
getTimeOfDay: () => getTimeOfDay,
|
|
90
|
+
getTimeOfWeek: () => getTimeOfWeek,
|
|
91
|
+
getTotalDaysFromTimeDifference: () => getTotalDaysFromTimeDifference,
|
|
92
|
+
getTtDate: () => getTtDate,
|
|
93
|
+
getUnixTime: () => getUnixTime,
|
|
94
|
+
getUtcDate: () => getUtcDate,
|
|
95
|
+
getWeekNumber: () => getWeekNumber,
|
|
96
|
+
getWeekOfYear: () => getWeekOfYear
|
|
97
|
+
});
|
|
98
|
+
module.exports = __toCommonJS(index_exports);
|
|
99
|
+
|
|
1
100
|
// src/constants/time.ts
|
|
2
101
|
var SECONDS_IN_WEEK = 604800;
|
|
3
102
|
var SECONDS_IN_DAY = 86400;
|
|
@@ -10,14 +109,12 @@ var MILLISECONDS_IN_MINUTE = 6e4;
|
|
|
10
109
|
var MILLISECONDS_IN_SECOND = 1e3;
|
|
11
110
|
var MILLISECONDS_TT_TAI = 32184;
|
|
12
111
|
var MILLISECONDS_GPS_TAI = 19e3;
|
|
13
|
-
var START_LEAP_SECS_GPS = 19;
|
|
14
112
|
var START_GPS_TIME = /* @__PURE__ */ new Date("1980-01-06T00:00:00Z");
|
|
15
113
|
var START_GAL_TIME = /* @__PURE__ */ new Date("1999-08-22T00:00:00Z");
|
|
16
|
-
var START_BDS_TIME = /* @__PURE__ */ new Date("2006-01-01T00:00:
|
|
17
|
-
var START_UNIX_TIME = /* @__PURE__ */ new Date("
|
|
114
|
+
var START_BDS_TIME = /* @__PURE__ */ new Date("2006-01-01T00:00:13Z");
|
|
115
|
+
var START_UNIX_TIME = /* @__PURE__ */ new Date("1969-12-31T23:59:49Z");
|
|
18
116
|
var START_NTP_TIME = /* @__PURE__ */ new Date("1900-01-01T00:00:00Z");
|
|
19
117
|
var START_GLO_LEAP = /* @__PURE__ */ new Date("1996-01-01T00:00:00Z");
|
|
20
|
-
var START_MJD2000_TIME = /* @__PURE__ */ new Date("2000-01-01T00:00:00Z");
|
|
21
118
|
var START_TAI_TIME = /* @__PURE__ */ new Date("1957-12-31T23:59:41Z");
|
|
22
119
|
var RINEX_CODES = [
|
|
23
120
|
"a",
|
|
@@ -45,12 +142,20 @@ var RINEX_CODES = [
|
|
|
45
142
|
"w",
|
|
46
143
|
"x"
|
|
47
144
|
];
|
|
48
|
-
var START_JULIAN_CALENDAR_UNIX_SECONDS = 24405875e-1;
|
|
49
145
|
var START_JULIAN_TAI = 24362045e-1;
|
|
50
146
|
var DAYS_MJD_JULIAN = 24000005e-1;
|
|
51
147
|
var DAYS_MJD2000_MJD = 51544.5;
|
|
52
148
|
var START_MJD_UNIX_SECONDS = 40587;
|
|
53
149
|
|
|
150
|
+
// src/types/enums.ts
|
|
151
|
+
var Scale = /* @__PURE__ */ ((Scale2) => {
|
|
152
|
+
Scale2[Scale2["TAI"] = 0] = "TAI";
|
|
153
|
+
Scale2[Scale2["TT"] = 1] = "TT";
|
|
154
|
+
Scale2[Scale2["GPS"] = 2] = "GPS";
|
|
155
|
+
Scale2[Scale2["UTC"] = 3] = "UTC";
|
|
156
|
+
return Scale2;
|
|
157
|
+
})(Scale || {});
|
|
158
|
+
|
|
54
159
|
// src/time/functions.ts
|
|
55
160
|
function getTimeOfDay(date) {
|
|
56
161
|
return (date.getTime() - Date.UTC(
|
|
@@ -164,6 +269,97 @@ function getTimeDifferenceFromObject(timeDifferenceObject) {
|
|
|
164
269
|
return getTimeDifferenceFromSeconds(seconds) + getTimeDifferenceFromMinutes(minutes) + getTimeDifferenceFromHours(hours) + getTimeDifferenceFromDays(days);
|
|
165
270
|
}
|
|
166
271
|
|
|
272
|
+
// src/time/utc.ts
|
|
273
|
+
function getLeap(date) {
|
|
274
|
+
const ntp_time = getNtpTime(date);
|
|
275
|
+
const leapSecondsMap = {
|
|
276
|
+
2272060800: 10,
|
|
277
|
+
// 1 Jan 1972
|
|
278
|
+
2287785600: 11,
|
|
279
|
+
// 1 Jul 1972
|
|
280
|
+
2303683200: 12,
|
|
281
|
+
// 1 Jan 1973
|
|
282
|
+
2335219200: 13,
|
|
283
|
+
// 1 Jan 1974
|
|
284
|
+
2366755200: 14,
|
|
285
|
+
// 1 Jan 1975
|
|
286
|
+
2398291200: 15,
|
|
287
|
+
// 1 Jan 1976
|
|
288
|
+
2429913600: 16,
|
|
289
|
+
// 1 Jan 1977
|
|
290
|
+
2461449600: 17,
|
|
291
|
+
// 1 Jan 1978
|
|
292
|
+
2492985600: 18,
|
|
293
|
+
// 1 Jan 1979
|
|
294
|
+
2524521600: 19,
|
|
295
|
+
// 1 Jan 1980
|
|
296
|
+
2571782400: 20,
|
|
297
|
+
// 1 Jul 1981
|
|
298
|
+
2603318400: 21,
|
|
299
|
+
// 1 Jul 1982
|
|
300
|
+
2634854400: 22,
|
|
301
|
+
// 1 Jul 1983
|
|
302
|
+
2698012800: 23,
|
|
303
|
+
// 1 Jul 1985
|
|
304
|
+
2776982400: 24,
|
|
305
|
+
// 1 Jan 1988
|
|
306
|
+
2840140800: 25,
|
|
307
|
+
// 1 Jan 1990
|
|
308
|
+
2871676800: 26,
|
|
309
|
+
// 1 Jan 1991
|
|
310
|
+
2918937600: 27,
|
|
311
|
+
// 1 Jul 1992
|
|
312
|
+
2950473600: 28,
|
|
313
|
+
// 1 Jul 1993
|
|
314
|
+
2982009600: 29,
|
|
315
|
+
// 1 Jul 1994
|
|
316
|
+
3029443200: 30,
|
|
317
|
+
// 1 Jan 1996
|
|
318
|
+
3076704e3: 31,
|
|
319
|
+
// 1 Jul 1997
|
|
320
|
+
3124137600: 32,
|
|
321
|
+
// 1 Jan 1999
|
|
322
|
+
3345062400: 33,
|
|
323
|
+
// 1 Jan 2006
|
|
324
|
+
3439756800: 34,
|
|
325
|
+
// 1 Jan 2009
|
|
326
|
+
3550089600: 35,
|
|
327
|
+
// 1 Jul 2012
|
|
328
|
+
3644697600: 36,
|
|
329
|
+
// 1 Jul 2015
|
|
330
|
+
3692217600: 37
|
|
331
|
+
// 1 Jan 2017
|
|
332
|
+
};
|
|
333
|
+
for (const [timestamp, leapSeconds] of Object.entries(
|
|
334
|
+
leapSecondsMap
|
|
335
|
+
).reverse()) {
|
|
336
|
+
if (ntp_time / MILLISECONDS_IN_SECOND - leapSeconds >= Number(timestamp)) {
|
|
337
|
+
return leapSeconds;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return 8;
|
|
341
|
+
}
|
|
342
|
+
function getGpsLeap(date) {
|
|
343
|
+
const leap_seconds = getLeap(date);
|
|
344
|
+
if (leap_seconds < 0) return 0;
|
|
345
|
+
return leap_seconds - 19;
|
|
346
|
+
}
|
|
347
|
+
function getUtcDate(date) {
|
|
348
|
+
const tai_date = getTaiDate(date);
|
|
349
|
+
const leap_seconds = getLeap(date);
|
|
350
|
+
return new Date(tai_date.getTime() - leap_seconds * MILLISECONDS_IN_SECOND);
|
|
351
|
+
}
|
|
352
|
+
function getDateFromUtc(utc_date) {
|
|
353
|
+
const tai_date = new Date(
|
|
354
|
+
utc_date.getTime() + getLeap(utc_date) * MILLISECONDS_IN_SECOND
|
|
355
|
+
);
|
|
356
|
+
const leap_seconds = getLeap(getDateFromTai(tai_date));
|
|
357
|
+
const gps_date = getDateFromTai(
|
|
358
|
+
new Date(utc_date.getTime() + leap_seconds * MILLISECONDS_IN_SECOND)
|
|
359
|
+
);
|
|
360
|
+
return gps_date;
|
|
361
|
+
}
|
|
362
|
+
|
|
167
363
|
// src/time/gnss.ts
|
|
168
364
|
function getGpsTime(date) {
|
|
169
365
|
return date.getTime() - START_GPS_TIME.getTime();
|
|
@@ -184,10 +380,11 @@ function getDateFromBdsTime(bdsTime) {
|
|
|
184
380
|
return new Date(bdsTime + START_BDS_TIME.getTime());
|
|
185
381
|
}
|
|
186
382
|
function getUnixTime(date) {
|
|
187
|
-
|
|
383
|
+
const utc_date = getUtcDate(date);
|
|
384
|
+
return utc_date.getTime();
|
|
188
385
|
}
|
|
189
386
|
function getDateFromUnixTime(unixTime) {
|
|
190
|
-
return new Date(unixTime
|
|
387
|
+
return getDateFromUtc(new Date(unixTime));
|
|
191
388
|
}
|
|
192
389
|
function getWeekNumber(date) {
|
|
193
390
|
return Math.floor(getGpsTime(date) / MILLISECONDS_IN_WEEK);
|
|
@@ -200,16 +397,16 @@ function getDateFromGpsData(weekNumber, timeOfWeek) {
|
|
|
200
397
|
weekNumber * MILLISECONDS_IN_WEEK + timeOfWeek * MILLISECONDS_IN_SECOND + START_GPS_TIME.getTime()
|
|
201
398
|
);
|
|
202
399
|
}
|
|
203
|
-
function
|
|
400
|
+
function getTaiDate(date) {
|
|
204
401
|
return new Date(date.getTime() + MILLISECONDS_GPS_TAI);
|
|
205
402
|
}
|
|
206
|
-
function
|
|
403
|
+
function getDateFromTai(tai_date) {
|
|
207
404
|
return new Date(tai_date.getTime() - MILLISECONDS_GPS_TAI);
|
|
208
405
|
}
|
|
209
|
-
function
|
|
406
|
+
function getTtDate(date) {
|
|
210
407
|
return new Date(date.getTime() + MILLISECONDS_GPS_TAI + MILLISECONDS_TT_TAI);
|
|
211
408
|
}
|
|
212
|
-
function
|
|
409
|
+
function getDateFromTt(tt_date) {
|
|
213
410
|
return new Date(
|
|
214
411
|
tt_date.getTime() - MILLISECONDS_GPS_TAI - MILLISECONDS_TT_TAI
|
|
215
412
|
);
|
|
@@ -232,7 +429,7 @@ function getDateFromGloN(n4, na, tod) {
|
|
|
232
429
|
return date;
|
|
233
430
|
}
|
|
234
431
|
function getNtpTime(date) {
|
|
235
|
-
return
|
|
432
|
+
return getTaiDate(date).getTime() - START_NTP_TIME.getTime();
|
|
236
433
|
}
|
|
237
434
|
|
|
238
435
|
// src/time/rinex.ts
|
|
@@ -264,110 +461,58 @@ function getDateFromRINEX(rinex) {
|
|
|
264
461
|
return date;
|
|
265
462
|
}
|
|
266
463
|
|
|
267
|
-
// src/time/utc.ts
|
|
268
|
-
function getLeap(date) {
|
|
269
|
-
const ntp_time = getNtpTime(date);
|
|
270
|
-
const leapSecondsMap = {
|
|
271
|
-
2272060800: 10,
|
|
272
|
-
// 1 Jan 1972
|
|
273
|
-
2287785600: 11,
|
|
274
|
-
// 1 Jul 1972
|
|
275
|
-
2303683200: 12,
|
|
276
|
-
// 1 Jan 1973
|
|
277
|
-
2335219200: 13,
|
|
278
|
-
// 1 Jan 1974
|
|
279
|
-
2366755200: 14,
|
|
280
|
-
// 1 Jan 1975
|
|
281
|
-
2398291200: 15,
|
|
282
|
-
// 1 Jan 1976
|
|
283
|
-
2429913600: 16,
|
|
284
|
-
// 1 Jan 1977
|
|
285
|
-
2461449600: 17,
|
|
286
|
-
// 1 Jan 1978
|
|
287
|
-
2492985600: 18,
|
|
288
|
-
// 1 Jan 1979
|
|
289
|
-
2524521600: 19,
|
|
290
|
-
// 1 Jan 1980
|
|
291
|
-
2571782400: 20,
|
|
292
|
-
// 1 Jul 1981
|
|
293
|
-
2603318400: 21,
|
|
294
|
-
// 1 Jul 1982
|
|
295
|
-
2634854400: 22,
|
|
296
|
-
// 1 Jul 1983
|
|
297
|
-
2698012800: 23,
|
|
298
|
-
// 1 Jul 1985
|
|
299
|
-
2776982400: 24,
|
|
300
|
-
// 1 Jan 1988
|
|
301
|
-
2840140800: 25,
|
|
302
|
-
// 1 Jan 1990
|
|
303
|
-
2871676800: 26,
|
|
304
|
-
// 1 Jan 1991
|
|
305
|
-
2918937600: 27,
|
|
306
|
-
// 1 Jul 1992
|
|
307
|
-
2950473600: 28,
|
|
308
|
-
// 1 Jul 1993
|
|
309
|
-
2982009600: 29,
|
|
310
|
-
// 1 Jul 1994
|
|
311
|
-
3029443200: 30,
|
|
312
|
-
// 1 Jan 1996
|
|
313
|
-
3076704e3: 31,
|
|
314
|
-
// 1 Jul 1997
|
|
315
|
-
3124137600: 32,
|
|
316
|
-
// 1 Jan 1999
|
|
317
|
-
3345062400: 33,
|
|
318
|
-
// 1 Jan 2006
|
|
319
|
-
3439756800: 34,
|
|
320
|
-
// 1 Jan 2009
|
|
321
|
-
3550089600: 35,
|
|
322
|
-
// 1 Jul 2012
|
|
323
|
-
3644697600: 36,
|
|
324
|
-
// 1 Jul 2015
|
|
325
|
-
3692217600: 37
|
|
326
|
-
// 1 Jan 2017
|
|
327
|
-
};
|
|
328
|
-
for (const [timestamp, leapSeconds] of Object.entries(
|
|
329
|
-
leapSecondsMap
|
|
330
|
-
).reverse()) {
|
|
331
|
-
if (ntp_time / MILLISECONDS_IN_SECOND - leapSeconds >= Number(timestamp)) {
|
|
332
|
-
return leapSeconds;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return 0;
|
|
336
|
-
}
|
|
337
|
-
function getGpsLeap(date) {
|
|
338
|
-
const leap_seconds = getLeap(date);
|
|
339
|
-
if (leap_seconds < 0)
|
|
340
|
-
return 0;
|
|
341
|
-
return leap_seconds - 19;
|
|
342
|
-
}
|
|
343
|
-
function getUtcDate(date) {
|
|
344
|
-
const tai_date = getTAIDate(date);
|
|
345
|
-
const leap_seconds = getLeap(date);
|
|
346
|
-
return new Date(tai_date.getTime() - leap_seconds * MILLISECONDS_IN_SECOND);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
464
|
// src/time/julian.ts
|
|
350
|
-
function getJulianDate(date) {
|
|
351
|
-
|
|
465
|
+
function getJulianDate(date, scale = 1 /* TT */) {
|
|
466
|
+
if (scale === 0 /* TAI */) {
|
|
467
|
+
return (date.getTime() - START_TAI_TIME.getTime()) / MILLISECONDS_IN_DAY + START_JULIAN_TAI;
|
|
468
|
+
}
|
|
469
|
+
if (scale === 2 /* GPS */) {
|
|
470
|
+
return (date.getTime() - START_TAI_TIME.getTime() - MILLISECONDS_GPS_TAI) / MILLISECONDS_IN_DAY + START_JULIAN_TAI;
|
|
471
|
+
}
|
|
472
|
+
if (scale === 3 /* UTC */) {
|
|
473
|
+
return (date.getTime() - START_TAI_TIME.getTime() - getLeap(date) * MILLISECONDS_IN_SECOND) / MILLISECONDS_IN_DAY + START_JULIAN_TAI;
|
|
474
|
+
}
|
|
475
|
+
return (date.getTime() - START_TAI_TIME.getTime() + MILLISECONDS_TT_TAI) / MILLISECONDS_IN_DAY + START_JULIAN_TAI;
|
|
352
476
|
}
|
|
353
|
-
function getDateFromJulianDate(julianDate) {
|
|
477
|
+
function getDateFromJulianDate(julianDate, scale = 1 /* TT */) {
|
|
478
|
+
if (scale === 0 /* TAI */) {
|
|
479
|
+
return new Date(
|
|
480
|
+
(julianDate - START_JULIAN_TAI) * MILLISECONDS_IN_DAY + START_TAI_TIME.getTime()
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
if (scale === 2 /* GPS */) {
|
|
484
|
+
return new Date(
|
|
485
|
+
(julianDate - START_JULIAN_TAI) * MILLISECONDS_IN_DAY + START_TAI_TIME.getTime() + MILLISECONDS_GPS_TAI
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
if (scale === 3 /* UTC */) {
|
|
489
|
+
const utc_date = new Date(
|
|
490
|
+
(julianDate - START_JULIAN_TAI) * MILLISECONDS_IN_DAY + START_TAI_TIME.getTime()
|
|
491
|
+
);
|
|
492
|
+
const tai_date = new Date(
|
|
493
|
+
utc_date.getTime() + getLeap(utc_date) * MILLISECONDS_IN_SECOND
|
|
494
|
+
);
|
|
495
|
+
const leap_seconds = getLeap(getDateFromTai(tai_date));
|
|
496
|
+
return new Date(utc_date.getTime() + leap_seconds * MILLISECONDS_IN_SECOND);
|
|
497
|
+
}
|
|
354
498
|
return new Date(
|
|
355
|
-
(julianDate -
|
|
499
|
+
(julianDate - START_JULIAN_TAI) * MILLISECONDS_IN_DAY + START_TAI_TIME.getTime() - MILLISECONDS_TT_TAI
|
|
356
500
|
);
|
|
357
501
|
}
|
|
358
|
-
function getMJD(date) {
|
|
359
|
-
return getJulianDate(date) - DAYS_MJD_JULIAN;
|
|
502
|
+
function getMJD(date, scale = 1 /* TT */) {
|
|
503
|
+
return getJulianDate(date, scale) - DAYS_MJD_JULIAN;
|
|
360
504
|
}
|
|
361
|
-
function getDateFromMJD(mjd) {
|
|
362
|
-
return getDateFromJulianDate(mjd + DAYS_MJD_JULIAN);
|
|
505
|
+
function getDateFromMJD(mjd, scale = 1 /* TT */) {
|
|
506
|
+
return getDateFromJulianDate(mjd + DAYS_MJD_JULIAN, scale);
|
|
363
507
|
}
|
|
364
|
-
function getMJD2000(date) {
|
|
365
|
-
return getMJD(date) - DAYS_MJD2000_MJD;
|
|
508
|
+
function getMJD2000(date, scale = 1 /* TT */) {
|
|
509
|
+
return getMJD(date, scale) - DAYS_MJD2000_MJD;
|
|
366
510
|
}
|
|
367
|
-
function getDateFromMJD2000(mjd2000) {
|
|
368
|
-
return getDateFromMJD(mjd2000 + DAYS_MJD2000_MJD);
|
|
511
|
+
function getDateFromMJD2000(mjd2000, scale = 1 /* TT */) {
|
|
512
|
+
return getDateFromMJD(mjd2000 + DAYS_MJD2000_MJD, scale);
|
|
369
513
|
}
|
|
370
|
-
export
|
|
514
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
515
|
+
0 && (module.exports = {
|
|
371
516
|
DAYS_MJD2000_MJD,
|
|
372
517
|
DAYS_MJD_JULIAN,
|
|
373
518
|
MILLISECONDS_GPS_TAI,
|
|
@@ -386,14 +531,12 @@ export {
|
|
|
386
531
|
START_GAL_TIME,
|
|
387
532
|
START_GLO_LEAP,
|
|
388
533
|
START_GPS_TIME,
|
|
389
|
-
START_JULIAN_CALENDAR_UNIX_SECONDS,
|
|
390
534
|
START_JULIAN_TAI,
|
|
391
|
-
START_LEAP_SECS_GPS,
|
|
392
|
-
START_MJD2000_TIME,
|
|
393
535
|
START_MJD_UNIX_SECONDS,
|
|
394
536
|
START_NTP_TIME,
|
|
395
537
|
START_TAI_TIME,
|
|
396
538
|
START_UNIX_TIME,
|
|
539
|
+
Scale,
|
|
397
540
|
getBdsTime,
|
|
398
541
|
getDateFromBdsTime,
|
|
399
542
|
getDateFromDayOfWeek,
|
|
@@ -407,10 +550,11 @@ export {
|
|
|
407
550
|
getDateFromMJD,
|
|
408
551
|
getDateFromMJD2000,
|
|
409
552
|
getDateFromRINEX,
|
|
410
|
-
|
|
411
|
-
getDateFromTT,
|
|
553
|
+
getDateFromTai,
|
|
412
554
|
getDateFromTimeOfDay,
|
|
555
|
+
getDateFromTt,
|
|
413
556
|
getDateFromUnixTime,
|
|
557
|
+
getDateFromUtc,
|
|
414
558
|
getDayOfWeek,
|
|
415
559
|
getDayOfYear,
|
|
416
560
|
getGalTime,
|
|
@@ -428,8 +572,7 @@ export {
|
|
|
428
572
|
getNtpTime,
|
|
429
573
|
getRINEX,
|
|
430
574
|
getSecondsFromTimeDifference,
|
|
431
|
-
|
|
432
|
-
getTTDate,
|
|
575
|
+
getTaiDate,
|
|
433
576
|
getTimeDifference,
|
|
434
577
|
getTimeDifferenceFromDays,
|
|
435
578
|
getTimeDifferenceFromHours,
|
|
@@ -439,8 +582,9 @@ export {
|
|
|
439
582
|
getTimeOfDay,
|
|
440
583
|
getTimeOfWeek,
|
|
441
584
|
getTotalDaysFromTimeDifference,
|
|
585
|
+
getTtDate,
|
|
442
586
|
getUnixTime,
|
|
443
587
|
getUtcDate,
|
|
444
588
|
getWeekNumber,
|
|
445
589
|
getWeekOfYear
|
|
446
|
-
};
|
|
590
|
+
});
|
|
@@ -17,22 +17,26 @@ declare const MILLISECONDS_IN_MINUTE: number;
|
|
|
17
17
|
declare const MILLISECONDS_IN_SECOND: number;
|
|
18
18
|
declare const MILLISECONDS_TT_TAI: number;
|
|
19
19
|
declare const MILLISECONDS_GPS_TAI: number;
|
|
20
|
-
declare const START_LEAP_SECS_GPS: number;
|
|
21
20
|
declare const START_GPS_TIME: Date;
|
|
22
21
|
declare const START_GAL_TIME: Date;
|
|
23
22
|
declare const START_BDS_TIME: Date;
|
|
24
23
|
declare const START_UNIX_TIME: Date;
|
|
25
24
|
declare const START_NTP_TIME: Date;
|
|
26
25
|
declare const START_GLO_LEAP: Date;
|
|
27
|
-
declare const START_MJD2000_TIME: Date;
|
|
28
26
|
declare const START_TAI_TIME: Date;
|
|
29
27
|
declare const RINEX_CODES: HourCode[];
|
|
30
|
-
declare const START_JULIAN_CALENDAR_UNIX_SECONDS = 2440587.5;
|
|
31
28
|
declare const START_JULIAN_TAI = 2436204.5;
|
|
32
29
|
declare const DAYS_MJD_JULIAN = 2400000.5;
|
|
33
30
|
declare const DAYS_MJD2000_MJD = 51544.5;
|
|
34
31
|
declare const START_MJD_UNIX_SECONDS = 40587;
|
|
35
32
|
|
|
33
|
+
declare enum Scale {
|
|
34
|
+
TAI = 0,
|
|
35
|
+
TT = 1,
|
|
36
|
+
GPS = 2,
|
|
37
|
+
UTC = 3
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
declare function getTimeOfDay(date: Date): number;
|
|
37
41
|
declare function getDateFromTimeOfDay(timeOfDay: number, dateRaw: Date): Date;
|
|
38
42
|
declare function getDayOfYear(date: Date): number;
|
|
@@ -54,17 +58,17 @@ declare function getDateFromUnixTime(unixTime: number): Date;
|
|
|
54
58
|
declare function getWeekNumber(date: Date): number;
|
|
55
59
|
declare function getTimeOfWeek(date: Date): number;
|
|
56
60
|
declare function getDateFromGpsData(weekNumber: number, timeOfWeek: number): Date;
|
|
57
|
-
declare function
|
|
58
|
-
declare function
|
|
59
|
-
declare function
|
|
60
|
-
declare function
|
|
61
|
+
declare function getTaiDate(date: Date): Date;
|
|
62
|
+
declare function getDateFromTai(tai_date: Date): Date;
|
|
63
|
+
declare function getTtDate(date: Date): Date;
|
|
64
|
+
declare function getDateFromTt(tt_date: Date): Date;
|
|
61
65
|
declare function getGloN4(date: Date): number;
|
|
62
66
|
declare function getGloNA(date: Date): number;
|
|
63
67
|
declare function getDateFromGloN(n4: number, na: number, tod: number): Date;
|
|
64
68
|
declare function getNtpTime(date: Date): number;
|
|
65
69
|
|
|
66
70
|
declare function getRINEX(date: Date): string;
|
|
67
|
-
declare function getDateFromRINEX(rinex: string): Date
|
|
71
|
+
declare function getDateFromRINEX(rinex: string): Date;
|
|
68
72
|
|
|
69
73
|
declare function getTimeDifference(startDate: Date, finalDate: Date): number;
|
|
70
74
|
declare function getSecondsFromTimeDifference(timeDifference: number): number;
|
|
@@ -80,12 +84,13 @@ declare function getTimeDifferenceFromObject(timeDifferenceObject: TimeDifferenc
|
|
|
80
84
|
declare function getLeap(date: Date): number;
|
|
81
85
|
declare function getGpsLeap(date: Date): number;
|
|
82
86
|
declare function getUtcDate(date: Date): Date;
|
|
87
|
+
declare function getDateFromUtc(utc_date: Date): Date;
|
|
83
88
|
|
|
84
|
-
declare function getJulianDate(date: Date): number;
|
|
85
|
-
declare function getDateFromJulianDate(julianDate: number): Date;
|
|
86
|
-
declare function getMJD(date: Date): number;
|
|
87
|
-
declare function getDateFromMJD(mjd: number): Date;
|
|
88
|
-
declare function getMJD2000(date: Date): number;
|
|
89
|
-
declare function getDateFromMJD2000(mjd2000: number): Date;
|
|
89
|
+
declare function getJulianDate(date: Date, scale?: Scale): number;
|
|
90
|
+
declare function getDateFromJulianDate(julianDate: number, scale?: Scale): Date;
|
|
91
|
+
declare function getMJD(date: Date, scale?: Scale): number;
|
|
92
|
+
declare function getDateFromMJD(mjd: number, scale?: Scale): Date;
|
|
93
|
+
declare function getMJD2000(date: Date, scale?: Scale): number;
|
|
94
|
+
declare function getDateFromMJD2000(mjd2000: number, scale?: Scale): Date;
|
|
90
95
|
|
|
91
|
-
export { DAYS_MJD2000_MJD, DAYS_MJD_JULIAN, type HourCode, MILLISECONDS_GPS_TAI, MILLISECONDS_IN_DAY, MILLISECONDS_IN_HOUR, MILLISECONDS_IN_MINUTE, MILLISECONDS_IN_SECOND, MILLISECONDS_IN_WEEK, MILLISECONDS_TT_TAI, RINEX_CODES, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, SECONDS_IN_WEEK, START_BDS_TIME, START_GAL_TIME, START_GLO_LEAP, START_GPS_TIME,
|
|
96
|
+
export { DAYS_MJD2000_MJD, DAYS_MJD_JULIAN, type HourCode, MILLISECONDS_GPS_TAI, MILLISECONDS_IN_DAY, MILLISECONDS_IN_HOUR, MILLISECONDS_IN_MINUTE, MILLISECONDS_IN_SECOND, MILLISECONDS_IN_WEEK, MILLISECONDS_TT_TAI, RINEX_CODES, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, SECONDS_IN_WEEK, START_BDS_TIME, START_GAL_TIME, START_GLO_LEAP, START_GPS_TIME, START_JULIAN_TAI, START_MJD_UNIX_SECONDS, START_NTP_TIME, START_TAI_TIME, START_UNIX_TIME, Scale, type TimeDifference, getBdsTime, getDateFromBdsTime, getDateFromDayOfWeek, getDateFromDayOfYear, getDateFromGalTime, getDateFromGloN, getDateFromGpsData, getDateFromGpsTime, getDateFromHourCode, getDateFromJulianDate, getDateFromMJD, getDateFromMJD2000, getDateFromRINEX, getDateFromTai, getDateFromTimeOfDay, getDateFromTt, getDateFromUnixTime, getDateFromUtc, getDayOfWeek, getDayOfYear, getGalTime, getGloN4, getGloNA, getGpsLeap, getGpsTime, getHourCode, getHoursFromTimeDifference, getJulianDate, getLeap, getMJD, getMJD2000, getMinutesFromTimeDifference, getNtpTime, getRINEX, getSecondsFromTimeDifference, getTaiDate, getTimeDifference, getTimeDifferenceFromDays, getTimeDifferenceFromHours, getTimeDifferenceFromMinutes, getTimeDifferenceFromObject, getTimeDifferenceFromSeconds, getTimeOfDay, getTimeOfWeek, getTotalDaysFromTimeDifference, getTtDate, getUnixTime, getUtcDate, getWeekNumber, getWeekOfYear };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,22 +17,26 @@ declare const MILLISECONDS_IN_MINUTE: number;
|
|
|
17
17
|
declare const MILLISECONDS_IN_SECOND: number;
|
|
18
18
|
declare const MILLISECONDS_TT_TAI: number;
|
|
19
19
|
declare const MILLISECONDS_GPS_TAI: number;
|
|
20
|
-
declare const START_LEAP_SECS_GPS: number;
|
|
21
20
|
declare const START_GPS_TIME: Date;
|
|
22
21
|
declare const START_GAL_TIME: Date;
|
|
23
22
|
declare const START_BDS_TIME: Date;
|
|
24
23
|
declare const START_UNIX_TIME: Date;
|
|
25
24
|
declare const START_NTP_TIME: Date;
|
|
26
25
|
declare const START_GLO_LEAP: Date;
|
|
27
|
-
declare const START_MJD2000_TIME: Date;
|
|
28
26
|
declare const START_TAI_TIME: Date;
|
|
29
27
|
declare const RINEX_CODES: HourCode[];
|
|
30
|
-
declare const START_JULIAN_CALENDAR_UNIX_SECONDS = 2440587.5;
|
|
31
28
|
declare const START_JULIAN_TAI = 2436204.5;
|
|
32
29
|
declare const DAYS_MJD_JULIAN = 2400000.5;
|
|
33
30
|
declare const DAYS_MJD2000_MJD = 51544.5;
|
|
34
31
|
declare const START_MJD_UNIX_SECONDS = 40587;
|
|
35
32
|
|
|
33
|
+
declare enum Scale {
|
|
34
|
+
TAI = 0,
|
|
35
|
+
TT = 1,
|
|
36
|
+
GPS = 2,
|
|
37
|
+
UTC = 3
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
declare function getTimeOfDay(date: Date): number;
|
|
37
41
|
declare function getDateFromTimeOfDay(timeOfDay: number, dateRaw: Date): Date;
|
|
38
42
|
declare function getDayOfYear(date: Date): number;
|
|
@@ -54,17 +58,17 @@ declare function getDateFromUnixTime(unixTime: number): Date;
|
|
|
54
58
|
declare function getWeekNumber(date: Date): number;
|
|
55
59
|
declare function getTimeOfWeek(date: Date): number;
|
|
56
60
|
declare function getDateFromGpsData(weekNumber: number, timeOfWeek: number): Date;
|
|
57
|
-
declare function
|
|
58
|
-
declare function
|
|
59
|
-
declare function
|
|
60
|
-
declare function
|
|
61
|
+
declare function getTaiDate(date: Date): Date;
|
|
62
|
+
declare function getDateFromTai(tai_date: Date): Date;
|
|
63
|
+
declare function getTtDate(date: Date): Date;
|
|
64
|
+
declare function getDateFromTt(tt_date: Date): Date;
|
|
61
65
|
declare function getGloN4(date: Date): number;
|
|
62
66
|
declare function getGloNA(date: Date): number;
|
|
63
67
|
declare function getDateFromGloN(n4: number, na: number, tod: number): Date;
|
|
64
68
|
declare function getNtpTime(date: Date): number;
|
|
65
69
|
|
|
66
70
|
declare function getRINEX(date: Date): string;
|
|
67
|
-
declare function getDateFromRINEX(rinex: string): Date
|
|
71
|
+
declare function getDateFromRINEX(rinex: string): Date;
|
|
68
72
|
|
|
69
73
|
declare function getTimeDifference(startDate: Date, finalDate: Date): number;
|
|
70
74
|
declare function getSecondsFromTimeDifference(timeDifference: number): number;
|
|
@@ -80,12 +84,13 @@ declare function getTimeDifferenceFromObject(timeDifferenceObject: TimeDifferenc
|
|
|
80
84
|
declare function getLeap(date: Date): number;
|
|
81
85
|
declare function getGpsLeap(date: Date): number;
|
|
82
86
|
declare function getUtcDate(date: Date): Date;
|
|
87
|
+
declare function getDateFromUtc(utc_date: Date): Date;
|
|
83
88
|
|
|
84
|
-
declare function getJulianDate(date: Date): number;
|
|
85
|
-
declare function getDateFromJulianDate(julianDate: number): Date;
|
|
86
|
-
declare function getMJD(date: Date): number;
|
|
87
|
-
declare function getDateFromMJD(mjd: number): Date;
|
|
88
|
-
declare function getMJD2000(date: Date): number;
|
|
89
|
-
declare function getDateFromMJD2000(mjd2000: number): Date;
|
|
89
|
+
declare function getJulianDate(date: Date, scale?: Scale): number;
|
|
90
|
+
declare function getDateFromJulianDate(julianDate: number, scale?: Scale): Date;
|
|
91
|
+
declare function getMJD(date: Date, scale?: Scale): number;
|
|
92
|
+
declare function getDateFromMJD(mjd: number, scale?: Scale): Date;
|
|
93
|
+
declare function getMJD2000(date: Date, scale?: Scale): number;
|
|
94
|
+
declare function getDateFromMJD2000(mjd2000: number, scale?: Scale): Date;
|
|
90
95
|
|
|
91
|
-
export { DAYS_MJD2000_MJD, DAYS_MJD_JULIAN, type HourCode, MILLISECONDS_GPS_TAI, MILLISECONDS_IN_DAY, MILLISECONDS_IN_HOUR, MILLISECONDS_IN_MINUTE, MILLISECONDS_IN_SECOND, MILLISECONDS_IN_WEEK, MILLISECONDS_TT_TAI, RINEX_CODES, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, SECONDS_IN_WEEK, START_BDS_TIME, START_GAL_TIME, START_GLO_LEAP, START_GPS_TIME,
|
|
96
|
+
export { DAYS_MJD2000_MJD, DAYS_MJD_JULIAN, type HourCode, MILLISECONDS_GPS_TAI, MILLISECONDS_IN_DAY, MILLISECONDS_IN_HOUR, MILLISECONDS_IN_MINUTE, MILLISECONDS_IN_SECOND, MILLISECONDS_IN_WEEK, MILLISECONDS_TT_TAI, RINEX_CODES, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, SECONDS_IN_WEEK, START_BDS_TIME, START_GAL_TIME, START_GLO_LEAP, START_GPS_TIME, START_JULIAN_TAI, START_MJD_UNIX_SECONDS, START_NTP_TIME, START_TAI_TIME, START_UNIX_TIME, Scale, type TimeDifference, getBdsTime, getDateFromBdsTime, getDateFromDayOfWeek, getDateFromDayOfYear, getDateFromGalTime, getDateFromGloN, getDateFromGpsData, getDateFromGpsTime, getDateFromHourCode, getDateFromJulianDate, getDateFromMJD, getDateFromMJD2000, getDateFromRINEX, getDateFromTai, getDateFromTimeOfDay, getDateFromTt, getDateFromUnixTime, getDateFromUtc, getDayOfWeek, getDayOfYear, getGalTime, getGloN4, getGloNA, getGpsLeap, getGpsTime, getHourCode, getHoursFromTimeDifference, getJulianDate, getLeap, getMJD, getMJD2000, getMinutesFromTimeDifference, getNtpTime, getRINEX, getSecondsFromTimeDifference, getTaiDate, getTimeDifference, getTimeDifferenceFromDays, getTimeDifferenceFromHours, getTimeDifferenceFromMinutes, getTimeDifferenceFromObject, getTimeDifferenceFromSeconds, getTimeOfDay, getTimeOfWeek, getTotalDaysFromTimeDifference, getTtDate, getUnixTime, getUtcDate, getWeekNumber, getWeekOfYear };
|