gnss-js 0.0.1 → 0.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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // src/constants.ts
1
+ // src/constants/time.ts
2
2
  var SECONDS_IN_WEEK = 604800;
3
3
  var SECONDS_IN_DAY = 86400;
4
4
  var SECONDS_IN_HOUR = 3600;
@@ -8,140 +8,56 @@ var MILLISECONDS_IN_DAY = 864e5;
8
8
  var MILLISECONDS_IN_HOUR = 36e5;
9
9
  var MILLISECONDS_IN_MINUTE = 6e4;
10
10
  var MILLISECONDS_IN_SECOND = 1e3;
11
- var SECONDS_TT_TAI = 32.184;
12
- var START_LEAP_SECS_GPS = 19;
13
- var START_GPS_TIME = new Date(Date.UTC(1980, 0, 6, 0, 0, 0, 0));
14
- var START_GAL_TIME = new Date(Date.UTC(1999, 7, 22, 0, 0, 0));
15
- var START_BDS_TIME = new Date(Date.UTC(2006, 0, 1, 0, 0, 0));
16
- var START_UNIX_TIME = new Date(Date.UTC(1970, 0, 1, 0, 0, 0));
17
- var START_MJD2000_TIME = new Date(Date.UTC(2e3, 0, 1, 0, 0, 0));
18
- var ALPHABET = "abcdefghijklmnopqrstuvwxyz".split("");
19
- var START_GLO_LEAP = new Date(Date.UTC(1996, 0, 1, 0, 0, 0, 0));
20
- var START_JULIAN_CALENDAR_UNIX_SECONDS = 24405875e-1;
11
+ var MILLISECONDS_TT_TAI = 32184;
12
+ var MILLISECONDS_GPS_TAI = 19e3;
13
+ var START_GPS_TIME = /* @__PURE__ */ new Date("1980-01-06T00:00:00Z");
14
+ var START_GAL_TIME = /* @__PURE__ */ new Date("1999-08-22T00:00:00Z");
15
+ var START_BDS_TIME = /* @__PURE__ */ new Date("2006-01-01T00:00:13Z");
16
+ var START_UNIX_TIME = /* @__PURE__ */ new Date("1969-12-31T23:59:49Z");
17
+ var START_NTP_TIME = /* @__PURE__ */ new Date("1900-01-01T00:00:00Z");
18
+ var START_GLO_LEAP = /* @__PURE__ */ new Date("1996-01-01T00:00:00Z");
19
+ var START_TAI_TIME = /* @__PURE__ */ new Date("1957-12-31T23:59:41Z");
20
+ var RINEX_CODES = [
21
+ "a",
22
+ "b",
23
+ "c",
24
+ "d",
25
+ "e",
26
+ "f",
27
+ "g",
28
+ "h",
29
+ "i",
30
+ "j",
31
+ "k",
32
+ "l",
33
+ "m",
34
+ "n",
35
+ "o",
36
+ "p",
37
+ "q",
38
+ "r",
39
+ "s",
40
+ "t",
41
+ "u",
42
+ "v",
43
+ "w",
44
+ "x"
45
+ ];
46
+ var START_JULIAN_TAI = 24362045e-1;
47
+ var DAYS_MJD_JULIAN = 24000005e-1;
48
+ var DAYS_MJD2000_MJD = 51544.5;
21
49
  var START_MJD_UNIX_SECONDS = 40587;
22
50
 
23
- // src/functions.ts
24
- function isValidDate(d) {
25
- return d instanceof Date && !Number.isNaN(d);
26
- }
27
- function getLeapSeconds(date) {
28
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 36922176e5) {
29
- return 37;
30
- }
31
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 36446976e5) {
32
- return 36;
33
- }
34
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 35500896e5) {
35
- return 35;
36
- }
37
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 34397568e5) {
38
- return 34;
39
- }
40
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 33450624e5) {
41
- return 33;
42
- }
43
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 31241376e5) {
44
- return 32;
45
- }
46
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 3076704e6) {
47
- return 31;
48
- }
49
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 30294432e5) {
50
- return 30;
51
- }
52
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 29820096e5) {
53
- return 29;
54
- }
55
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 29504736e5) {
56
- return 28;
57
- }
58
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 29189376e5) {
59
- return 27;
60
- }
61
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 28716768e5) {
62
- return 26;
63
- }
64
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 28401408e5) {
65
- return 25;
66
- }
67
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 27769824e5) {
68
- return 24;
69
- }
70
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 26980128e5) {
71
- return 23;
72
- }
73
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 26348544e5) {
74
- return 22;
75
- }
76
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 26033184e5) {
77
- return 21;
78
- }
79
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 25717824e5) {
80
- return 20;
81
- }
82
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 25245216e5) {
83
- return 19;
84
- }
85
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 24929856e5) {
86
- return 18;
87
- }
88
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 24614496e5) {
89
- return 17;
90
- }
91
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 24299136e5) {
92
- return 16;
93
- }
94
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 23982912e5) {
95
- return 15;
96
- }
97
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 23667552e5) {
98
- return 14;
99
- }
100
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 23352192e5) {
101
- return 13;
102
- }
103
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 23036832e5) {
104
- return 12;
105
- }
106
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 22877856e5) {
107
- return 11;
108
- }
109
- if (date.getTime() >= Date.UTC(1900, 0, 1) + 22720608e5) {
110
- return 10;
111
- }
112
- return 0;
113
- }
114
- function getGpsTime(date) {
115
- return date.getTime() - START_GPS_TIME.getTime();
116
- }
117
- function getGalTime(date) {
118
- return date.getTime() - START_GAL_TIME.getTime();
119
- }
120
- function getBdsTime(date) {
121
- return date.getTime() - START_BDS_TIME.getTime();
122
- }
123
- function getUnixTime(date) {
124
- return date.getTime() - START_UNIX_TIME.getTime();
125
- }
126
- function getWeekNumber(date) {
127
- return Math.floor(getGpsTime(date) / MILLISECONDS_IN_WEEK);
128
- }
129
- function getTimeOfWeek(date) {
130
- return Math.floor(
131
- getGpsTime(date) % MILLISECONDS_IN_WEEK / MILLISECONDS_IN_SECOND
132
- );
133
- }
51
+ // src/time/functions.ts
134
52
  function getTimeOfDay(date) {
135
- return Math.floor(
136
- (date.getTime() - Date.UTC(
137
- date.getUTCFullYear(),
138
- date.getUTCMonth(),
139
- date.getUTCDate(),
140
- 0,
141
- 0,
142
- 0
143
- )) / MILLISECONDS_IN_SECOND
144
- );
53
+ return (date.getTime() - Date.UTC(
54
+ date.getUTCFullYear(),
55
+ date.getUTCMonth(),
56
+ date.getUTCDate(),
57
+ 0,
58
+ 0,
59
+ 0
60
+ )) / MILLISECONDS_IN_SECOND;
145
61
  }
146
62
  function getDateFromTimeOfDay(timeOfDay, dateRaw) {
147
63
  const date = new Date(
@@ -154,68 +70,12 @@ function getDateFromTimeOfDay(timeOfDay, dateRaw) {
154
70
  0
155
71
  ) + timeOfDay * MILLISECONDS_IN_SECOND
156
72
  );
157
- if (!isValidDate(date))
158
- return void 0;
159
- return date;
160
- }
161
- function getGloN4(date) {
162
- return Math.floor((date.getUTCFullYear() - START_GLO_LEAP.getFullYear()) / 4);
163
- }
164
- function getGloNA(date) {
165
- const n4 = getGloN4(date);
166
- const init4YearPeriod = new Date(START_GLO_LEAP);
167
- init4YearPeriod.setUTCFullYear(init4YearPeriod.getUTCFullYear() + n4 * 4);
168
- return Math.floor(getTimeDifference(init4YearPeriod, date) / MILLISECONDS_IN_DAY) + 1;
169
- }
170
- function getDateFromGpsData(weekNumber, timeOfWeek) {
171
- const date = new Date(
172
- weekNumber * MILLISECONDS_IN_WEEK + timeOfWeek * MILLISECONDS_IN_SECOND + START_GPS_TIME.getTime()
173
- );
174
- if (!isValidDate(date))
175
- return void 0;
176
73
  return date;
177
74
  }
178
- function getDateFromGpsTime(gpsTime) {
179
- const date = new Date(
180
- gpsTime * MILLISECONDS_IN_SECOND + START_GPS_TIME.getTime()
181
- );
182
- if (!isValidDate(date))
183
- return void 0;
184
- return date;
185
- }
186
- function getDateFromGalTime(galTime) {
187
- const date = new Date(
188
- galTime * MILLISECONDS_IN_SECOND + START_GAL_TIME.getTime()
189
- );
190
- if (!isValidDate(date))
191
- return void 0;
192
- return date;
193
- }
194
- function getDateFromBdsTime(bdsTime) {
195
- const date = new Date(
196
- bdsTime * MILLISECONDS_IN_SECOND + START_BDS_TIME.getTime()
197
- );
198
- if (!isValidDate(date))
199
- return void 0;
200
- return date;
201
- }
202
- function getDateFromUnixTime(unixTime) {
203
- const date = new Date(
204
- unixTime * MILLISECONDS_IN_SECOND + START_UNIX_TIME.getTime()
205
- );
206
- if (!isValidDate(date))
207
- return void 0;
208
- return date;
209
- }
210
- function getDateFromGloN(n4, na, tod) {
211
- const date = new Date(START_GLO_LEAP);
212
- date.setFullYear(date.getUTCFullYear() + n4 * 4);
213
- date.setTime(
214
- date.getTime() + (na - 1) * MILLISECONDS_IN_DAY + tod * MILLISECONDS_IN_SECOND
215
- );
216
- if (!isValidDate(date))
217
- return void 0;
218
- return date;
75
+ function getDayOfYear(date) {
76
+ return Math.floor(
77
+ (date.getTime() - Date.UTC(date.getUTCFullYear())) / MILLISECONDS_IN_DAY
78
+ ) + 1;
219
79
  }
220
80
  function getDateFromDayOfYear(dayOfYear, date) {
221
81
  return new Date(
@@ -230,121 +90,58 @@ function getDateFromDayOfYear(dayOfYear, date) {
230
90
  ) + (dayOfYear - 1) * MILLISECONDS_IN_DAY
231
91
  );
232
92
  }
233
- function getDayOfYear(date) {
234
- return Math.floor(
235
- (date.getTime() - Date.UTC(date.getUTCFullYear())) / MILLISECONDS_IN_DAY
236
- ) + 1;
237
- }
238
93
  function getDayOfWeek(date) {
239
94
  return date.getUTCDay();
240
95
  }
241
96
  function getDateFromDayOfWeek(dayOfWeek, dateRaw) {
242
97
  if (dayOfWeek < 0 || dayOfWeek > 6)
243
98
  throw new Error("Day of week must be a value between 0 and 7");
244
- const date = new Date(
99
+ return new Date(
245
100
  dateRaw.getTime() + (dayOfWeek - dateRaw.getUTCDay()) * MILLISECONDS_IN_DAY
246
101
  );
247
- if (!isValidDate(date))
248
- return void 0;
249
- return date;
250
102
  }
251
103
  function getDateFromHourCode(hourCode, date) {
252
- const hour = ALPHABET.indexOf(hourCode);
253
- if (hour !== -1) {
254
- const newDate = new Date(date.getTime());
255
- newDate.setUTCHours(hour);
256
- return newDate;
257
- }
258
- return void 0;
104
+ const hour = RINEX_CODES.indexOf(hourCode);
105
+ if (hour === -1)
106
+ throw new Error("Hour code must be a lowercase letter between a and x");
107
+ const newDate = new Date(date.getTime());
108
+ newDate.setUTCHours(hour);
109
+ return newDate;
259
110
  }
260
111
  function getHourCode(date) {
261
- return ALPHABET[date.getUTCHours()];
262
- }
263
- function getJulianDate(date) {
264
- return date.getTime() / MILLISECONDS_IN_DAY + START_JULIAN_CALENDAR_UNIX_SECONDS;
265
- }
266
- function getDateFromJulianDate(julianDate) {
267
- const date = new Date(
268
- (julianDate - START_JULIAN_CALENDAR_UNIX_SECONDS) * MILLISECONDS_IN_DAY
269
- );
270
- if (!isValidDate(date))
271
- return void 0;
272
- return date;
273
- }
274
- function getMJD(date) {
275
- return date.getTime() / MILLISECONDS_IN_DAY + START_MJD_UNIX_SECONDS;
112
+ return RINEX_CODES[date.getUTCHours()];
276
113
  }
277
- function getDateFromMJD(mjd) {
278
- if (Number.isNaN(mjd))
279
- return void 0;
280
- const date = new Date((mjd - START_MJD_UNIX_SECONDS) * MILLISECONDS_IN_DAY);
281
- if (!isValidDate(date))
282
- return void 0;
283
- return date;
284
- }
285
- function getDateFromMJD2000(mjd2000) {
286
- const date = new Date(
287
- (mjd2000 - START_MJD_UNIX_SECONDS + 51544) * MILLISECONDS_IN_DAY
114
+ function getWeekOfYear(date) {
115
+ const target = new Date(
116
+ Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())
288
117
  );
289
- if (!isValidDate(date))
290
- return void 0;
291
- return date;
292
- }
293
- function getDateFromRINEX(rinex) {
294
- const year = Number.parseInt(rinex.substring(2, 6));
295
- const month = Number.parseInt(rinex.substring(7, 9)) - 1;
296
- const day = Number.parseInt(rinex.substring(10, 12));
297
- const hour = Number.parseInt(rinex.substring(13, 15));
298
- const minute = Number.parseInt(rinex.substring(16, 18));
299
- const second = Number.parseInt(rinex.substring(19, 21));
300
- const millisecond = Number.parseInt(rinex.substring(22, 29)) / 1e4;
301
- const date = new Date(
302
- Date.UTC(year, month, day, hour, minute, second, millisecond)
303
- );
304
- if (!isValidDate(date))
305
- return void 0;
306
- return date;
307
- }
308
- function getLeapSecondsFromTAI(date) {
309
- const leapsTAI = getLeapSeconds(date);
310
- const dateUTC = new Date(date.getTime() - leapsTAI * MILLISECONDS_IN_SECOND);
311
- const leapsUTC = getLeapSeconds(dateUTC);
312
- const dateTAI = new Date(date.getTime() + leapsUTC * MILLISECONDS_IN_SECOND);
313
- if (dateTAI.getTime() === date.getTime()) {
314
- return leapsTAI;
315
- }
316
- if (dateTAI.getTime() < date.getTime()) {
317
- return leapsTAI - 1;
318
- }
319
- return 0;
118
+ const dayNr = (target.getUTCDay() + 6) % 7;
119
+ target.setUTCDate(target.getUTCDate() - dayNr + 3);
120
+ const firstThursday = new Date(Date.UTC(target.getUTCFullYear(), 0, 4));
121
+ const dayDiff = (target.getTime() - firstThursday.getTime()) / (86400 * 1e3);
122
+ return 1 + Math.floor(dayDiff / 7) + 1;
320
123
  }
124
+
125
+ // src/time/time-difference.ts
321
126
  function getTimeDifference(startDate, finalDate) {
322
127
  return Math.floor(finalDate.getTime() - startDate.getTime());
323
128
  }
324
129
  function getSecondsFromTimeDifference(timeDifference) {
325
- if (Number.isNaN(timeDifference))
326
- return void 0;
327
130
  return Math.floor(
328
131
  timeDifference % MILLISECONDS_IN_MINUTE / MILLISECONDS_IN_SECOND
329
132
  );
330
133
  }
331
134
  function getMinutesFromTimeDifference(timeDifference) {
332
- if (Number.isNaN(timeDifference))
333
- return void 0;
334
135
  return Math.floor(
335
136
  timeDifference % MILLISECONDS_IN_HOUR / MILLISECONDS_IN_MINUTE
336
137
  );
337
138
  }
338
139
  function getHoursFromTimeDifference(timeDifference) {
339
- if (Number.isNaN(timeDifference))
340
- return void 0;
341
140
  return Math.floor(
342
141
  timeDifference % MILLISECONDS_IN_DAY / MILLISECONDS_IN_HOUR
343
142
  );
344
143
  }
345
144
  function getTotalDaysFromTimeDifference(timeDifference) {
346
- if (Number.isNaN(timeDifference))
347
- return void 0;
348
145
  return Math.floor(timeDifference / MILLISECONDS_IN_DAY);
349
146
  }
350
147
  function getTimeDifferenceFromSeconds(seconds) {
@@ -361,33 +158,246 @@ function getTimeDifferenceFromDays(days) {
361
158
  }
362
159
  function getTimeDifferenceFromObject(timeDifferenceObject) {
363
160
  const { seconds, minutes, hours, days } = timeDifferenceObject;
364
- if (Number.isNaN(seconds) || Number.isNaN(minutes) || Number.isNaN(hours) || Number.isNaN(days))
365
- return void 0;
366
161
  return getTimeDifferenceFromSeconds(seconds) + getTimeDifferenceFromMinutes(minutes) + getTimeDifferenceFromHours(hours) + getTimeDifferenceFromDays(days);
367
162
  }
163
+
164
+ // src/time/utc.ts
165
+ function getLeap(date) {
166
+ const ntp_time = getNtpTime(date);
167
+ const leapSecondsMap = {
168
+ 2272060800: 10,
169
+ // 1 Jan 1972
170
+ 2287785600: 11,
171
+ // 1 Jul 1972
172
+ 2303683200: 12,
173
+ // 1 Jan 1973
174
+ 2335219200: 13,
175
+ // 1 Jan 1974
176
+ 2366755200: 14,
177
+ // 1 Jan 1975
178
+ 2398291200: 15,
179
+ // 1 Jan 1976
180
+ 2429913600: 16,
181
+ // 1 Jan 1977
182
+ 2461449600: 17,
183
+ // 1 Jan 1978
184
+ 2492985600: 18,
185
+ // 1 Jan 1979
186
+ 2524521600: 19,
187
+ // 1 Jan 1980
188
+ 2571782400: 20,
189
+ // 1 Jul 1981
190
+ 2603318400: 21,
191
+ // 1 Jul 1982
192
+ 2634854400: 22,
193
+ // 1 Jul 1983
194
+ 2698012800: 23,
195
+ // 1 Jul 1985
196
+ 2776982400: 24,
197
+ // 1 Jan 1988
198
+ 2840140800: 25,
199
+ // 1 Jan 1990
200
+ 2871676800: 26,
201
+ // 1 Jan 1991
202
+ 2918937600: 27,
203
+ // 1 Jul 1992
204
+ 2950473600: 28,
205
+ // 1 Jul 1993
206
+ 2982009600: 29,
207
+ // 1 Jul 1994
208
+ 3029443200: 30,
209
+ // 1 Jan 1996
210
+ 3076704e3: 31,
211
+ // 1 Jul 1997
212
+ 3124137600: 32,
213
+ // 1 Jan 1999
214
+ 3345062400: 33,
215
+ // 1 Jan 2006
216
+ 3439756800: 34,
217
+ // 1 Jan 2009
218
+ 3550089600: 35,
219
+ // 1 Jul 2012
220
+ 3644697600: 36,
221
+ // 1 Jul 2015
222
+ 3692217600: 37
223
+ // 1 Jan 2017
224
+ };
225
+ for (const [timestamp, leapSeconds] of Object.entries(
226
+ leapSecondsMap
227
+ ).reverse()) {
228
+ if (ntp_time / MILLISECONDS_IN_SECOND - leapSeconds >= Number(timestamp)) {
229
+ return leapSeconds;
230
+ }
231
+ }
232
+ return 8;
233
+ }
234
+ function getGpsLeap(date) {
235
+ const leap_seconds = getLeap(date);
236
+ if (leap_seconds < 0)
237
+ return 0;
238
+ return leap_seconds - 19;
239
+ }
240
+ function getUtcDate(date) {
241
+ const tai_date = getTaiDate(date);
242
+ const leap_seconds = getLeap(date);
243
+ return new Date(tai_date.getTime() - leap_seconds * MILLISECONDS_IN_SECOND);
244
+ }
245
+ function getDateFromUtc(utc_date) {
246
+ const tai_date = new Date(
247
+ utc_date.getTime() + getLeap(utc_date) * MILLISECONDS_IN_SECOND
248
+ );
249
+ const leap_seconds = getLeap(getDateFromTai(tai_date));
250
+ const gps_date = getDateFromTai(
251
+ new Date(utc_date.getTime() + leap_seconds * MILLISECONDS_IN_SECOND)
252
+ );
253
+ return gps_date;
254
+ }
255
+
256
+ // src/time/gnss.ts
257
+ function getGpsTime(date) {
258
+ return date.getTime() - START_GPS_TIME.getTime();
259
+ }
260
+ function getDateFromGpsTime(gpsTime) {
261
+ return new Date(gpsTime + START_GPS_TIME.getTime());
262
+ }
263
+ function getGalTime(date) {
264
+ return date.getTime() - START_GAL_TIME.getTime();
265
+ }
266
+ function getDateFromGalTime(galTime) {
267
+ return new Date(galTime + START_GAL_TIME.getTime());
268
+ }
269
+ function getBdsTime(date) {
270
+ return date.getTime() - START_BDS_TIME.getTime();
271
+ }
272
+ function getDateFromBdsTime(bdsTime) {
273
+ return new Date(bdsTime + START_BDS_TIME.getTime());
274
+ }
275
+ function getUnixTime(date) {
276
+ const utc_date = getUtcDate(date);
277
+ return utc_date.getTime();
278
+ }
279
+ function getDateFromUnixTime(unixTime) {
280
+ return getDateFromUtc(new Date(unixTime));
281
+ }
282
+ function getWeekNumber(date) {
283
+ return Math.floor(getGpsTime(date) / MILLISECONDS_IN_WEEK);
284
+ }
285
+ function getTimeOfWeek(date) {
286
+ return getGpsTime(date) % MILLISECONDS_IN_WEEK / MILLISECONDS_IN_SECOND;
287
+ }
288
+ function getDateFromGpsData(weekNumber, timeOfWeek) {
289
+ return new Date(
290
+ weekNumber * MILLISECONDS_IN_WEEK + timeOfWeek * MILLISECONDS_IN_SECOND + START_GPS_TIME.getTime()
291
+ );
292
+ }
293
+ function getTaiDate(date) {
294
+ return new Date(date.getTime() + MILLISECONDS_GPS_TAI);
295
+ }
296
+ function getDateFromTai(tai_date) {
297
+ return new Date(tai_date.getTime() - MILLISECONDS_GPS_TAI);
298
+ }
299
+ function getTtDate(date) {
300
+ return new Date(date.getTime() + MILLISECONDS_GPS_TAI + MILLISECONDS_TT_TAI);
301
+ }
302
+ function getDateFromTt(tt_date) {
303
+ return new Date(
304
+ tt_date.getTime() - MILLISECONDS_GPS_TAI - MILLISECONDS_TT_TAI
305
+ );
306
+ }
307
+ function getGloN4(date) {
308
+ return Math.floor((date.getUTCFullYear() - START_GLO_LEAP.getFullYear()) / 4);
309
+ }
310
+ function getGloNA(date) {
311
+ const n4 = getGloN4(date);
312
+ const init4YearPeriod = new Date(START_GLO_LEAP);
313
+ init4YearPeriod.setUTCFullYear(init4YearPeriod.getUTCFullYear() + n4 * 4);
314
+ return Math.floor(getTimeDifference(init4YearPeriod, date) / MILLISECONDS_IN_DAY) + 1;
315
+ }
316
+ function getDateFromGloN(n4, na, tod) {
317
+ const date = new Date(START_GLO_LEAP);
318
+ date.setFullYear(date.getUTCFullYear() + n4 * 4);
319
+ date.setTime(
320
+ date.getTime() + (na - 1) * MILLISECONDS_IN_DAY + tod * MILLISECONDS_IN_SECOND
321
+ );
322
+ return date;
323
+ }
324
+ function getNtpTime(date) {
325
+ return getTaiDate(date).getTime() - START_NTP_TIME.getTime();
326
+ }
327
+
328
+ // src/time/rinex.ts
368
329
  function getRINEX(date) {
369
- return "> " + date.getUTCFullYear() + " " + (date.getUTCMonth() + 1).toString().padStart(2, "0") + " " + date.getUTCDate().toString().padStart(2, "0") + " " + date.getUTCHours().toString().padStart(2, "0") + " " + date.getUTCMinutes().toString().padStart(2, "0") + " " + (date.getUTCMilliseconds() / MILLISECONDS_IN_SECOND + date.getUTCSeconds()).toFixed(7).padStart(2, "0");
330
+ const seconds = date.getUTCSeconds();
331
+ const milliseconds = date.getUTCMilliseconds();
332
+ const fractionalSeconds = (milliseconds / MILLISECONDS_IN_SECOND).toFixed(7).slice(1);
333
+ const formatted = `> ${date.getUTCFullYear()} ${String(
334
+ date.getUTCMonth() + 1
335
+ ).padStart(2, "0")} ${String(date.getUTCDate()).padStart(2, "0")} ${String(
336
+ date.getUTCHours()
337
+ ).padStart(2, "0")} ${String(date.getUTCMinutes()).padStart(
338
+ 2,
339
+ "0"
340
+ )} ${String(seconds).padStart(2, "0")}${fractionalSeconds}`;
341
+ return formatted;
342
+ }
343
+ function getDateFromRINEX(rinex) {
344
+ const year = Number.parseInt(rinex.substring(2, 6));
345
+ const month = Number.parseInt(rinex.substring(7, 9)) - 1;
346
+ const day = Number.parseInt(rinex.substring(10, 12));
347
+ const hour = Number.parseInt(rinex.substring(13, 15));
348
+ const minute = Number.parseInt(rinex.substring(16, 18));
349
+ const second = Number.parseInt(rinex.substring(19, 21));
350
+ const millisecond = Number.parseInt(rinex.substring(22, 29)) / 1e4;
351
+ const date = new Date(
352
+ Date.UTC(year, month, day, hour, minute, second, millisecond)
353
+ );
354
+ return date;
355
+ }
356
+
357
+ // src/time/julian.ts
358
+ function getJulianDate(date) {
359
+ return (date.getTime() - START_TAI_TIME.getTime()) / MILLISECONDS_IN_DAY + START_JULIAN_TAI;
360
+ }
361
+ function getDateFromJulianDate(julianDate) {
362
+ return new Date(
363
+ (julianDate - 24362045e-1) * MILLISECONDS_IN_DAY + START_TAI_TIME.getTime()
364
+ );
365
+ }
366
+ function getMJD(date) {
367
+ return getJulianDate(date) - DAYS_MJD_JULIAN;
368
+ }
369
+ function getDateFromMJD(mjd) {
370
+ return getDateFromJulianDate(mjd + DAYS_MJD_JULIAN);
371
+ }
372
+ function getMJD2000(date) {
373
+ return getMJD(date) - DAYS_MJD2000_MJD;
374
+ }
375
+ function getDateFromMJD2000(mjd2000) {
376
+ return getDateFromMJD(mjd2000 + DAYS_MJD2000_MJD);
370
377
  }
371
378
  export {
372
- ALPHABET,
379
+ DAYS_MJD2000_MJD,
380
+ DAYS_MJD_JULIAN,
381
+ MILLISECONDS_GPS_TAI,
373
382
  MILLISECONDS_IN_DAY,
374
383
  MILLISECONDS_IN_HOUR,
375
384
  MILLISECONDS_IN_MINUTE,
376
385
  MILLISECONDS_IN_SECOND,
377
386
  MILLISECONDS_IN_WEEK,
387
+ MILLISECONDS_TT_TAI,
388
+ RINEX_CODES,
378
389
  SECONDS_IN_DAY,
379
390
  SECONDS_IN_HOUR,
380
391
  SECONDS_IN_MINUTE,
381
392
  SECONDS_IN_WEEK,
382
- SECONDS_TT_TAI,
383
393
  START_BDS_TIME,
384
394
  START_GAL_TIME,
385
395
  START_GLO_LEAP,
386
396
  START_GPS_TIME,
387
- START_JULIAN_CALENDAR_UNIX_SECONDS,
388
- START_LEAP_SECS_GPS,
389
- START_MJD2000_TIME,
397
+ START_JULIAN_TAI,
390
398
  START_MJD_UNIX_SECONDS,
399
+ START_NTP_TIME,
400
+ START_TAI_TIME,
391
401
  START_UNIX_TIME,
392
402
  getBdsTime,
393
403
  getDateFromBdsTime,
@@ -402,23 +412,29 @@ export {
402
412
  getDateFromMJD,
403
413
  getDateFromMJD2000,
404
414
  getDateFromRINEX,
415
+ getDateFromTai,
405
416
  getDateFromTimeOfDay,
417
+ getDateFromTt,
406
418
  getDateFromUnixTime,
419
+ getDateFromUtc,
407
420
  getDayOfWeek,
408
421
  getDayOfYear,
409
422
  getGalTime,
410
423
  getGloN4,
411
424
  getGloNA,
425
+ getGpsLeap,
412
426
  getGpsTime,
413
427
  getHourCode,
414
428
  getHoursFromTimeDifference,
415
429
  getJulianDate,
416
- getLeapSeconds,
417
- getLeapSecondsFromTAI,
430
+ getLeap,
418
431
  getMJD,
432
+ getMJD2000,
419
433
  getMinutesFromTimeDifference,
434
+ getNtpTime,
420
435
  getRINEX,
421
436
  getSecondsFromTimeDifference,
437
+ getTaiDate,
422
438
  getTimeDifference,
423
439
  getTimeDifferenceFromDays,
424
440
  getTimeDifferenceFromHours,
@@ -428,6 +444,9 @@ export {
428
444
  getTimeOfDay,
429
445
  getTimeOfWeek,
430
446
  getTotalDaysFromTimeDifference,
447
+ getTtDate,
431
448
  getUnixTime,
432
- getWeekNumber
449
+ getUtcDate,
450
+ getWeekNumber,
451
+ getWeekOfYear
433
452
  };
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ testMatch: ['**/test/**/*.test.js'],
5
+ moduleDirectories: ['node_modules', '<rootDir>'],
6
+ };