From 0419a86e4eaa8e29f2281bbee3b3b01f559ec7f4 Mon Sep 17 00:00:00 2001 From: Theodore Kruczek Date: Mon, 15 Jan 2024 18:47:28 -0500 Subject: [PATCH] refactor: :label: add more typing for Seconds in Epoch calculations --- src/body/Sun.ts | 3 ++- src/coordinate/Tle.ts | 2 +- src/time/EpochGPS.ts | 7 ++++--- src/time/EpochUTC.ts | 9 +++++---- tsconfig.base.json | 3 --- tsconfig.json | 2 -- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/body/Sun.ts b/src/body/Sun.ts index 0eb4ed9..2324b21 100644 --- a/src/body/Sun.ts +++ b/src/body/Sun.ts @@ -51,6 +51,7 @@ import { RAD2DEG, RaDec, Radians, + Seconds, SunTime, TAU, Vector3D, @@ -522,7 +523,7 @@ export class Sun { const distance = Sun.position(epoch).magnitude(); const dSec = distance / cKmPerSec; - return Sun.position(epoch.roll(-dSec)); + return Sun.position(epoch.roll(-dSec as Seconds)); } /** diff --git a/src/coordinate/Tle.ts b/src/coordinate/Tle.ts index 578fb76..ac45a7a 100644 --- a/src/coordinate/Tle.ts +++ b/src/coordinate/Tle.ts @@ -222,7 +222,7 @@ export class Tle { } const days = parseFloat(epochStr.substring(2, 14)) - 1; - return EpochUTC.fromDateTimeString(`${year}-01-01T00:00:00.000Z`).roll(days * secondsPerDay); + return EpochUTC.fromDateTimeString(`${year}-01-01T00:00:00.000Z`).roll(days * secondsPerDay as Seconds); } /** diff --git a/src/time/EpochGPS.ts b/src/time/EpochGPS.ts index 2d33913..f18e2a0 100644 --- a/src/time/EpochGPS.ts +++ b/src/time/EpochGPS.ts @@ -21,6 +21,7 @@ * SOFTWARE. */ +import { Seconds } from '../main'; import { DataHandler } from '../data/DataHandler'; import { secondsPerWeek } from '../utils/constants'; import type { EpochUTC } from './EpochUTC'; @@ -49,7 +50,7 @@ export class EpochGPS { static reference: EpochUTC; // / GPS leap second difference from TAI/UTC offsets. - static offset = 19; + static offset = 19 as Seconds; // / Get GPS week accounting for 10-bit rollover. get week10Bit(): number { @@ -67,9 +68,9 @@ export class EpochGPS { // / Convert this to a UTC epoch. toUTC(): EpochUTC { - const init = EpochGPS.reference.roll(this.week * secondsPerWeek + this.seconds); + const init = EpochGPS.reference.roll((this.week * secondsPerWeek + this.seconds) as Seconds); const ls = DataHandler.getInstance().getLeapSeconds(init.toJulianDate()); - return init.roll(-(ls - EpochGPS.offset)); + return init.roll(-(ls - EpochGPS.offset) as Seconds); } } diff --git a/src/time/EpochUTC.ts b/src/time/EpochUTC.ts index d91e756..7e0b0d4 100644 --- a/src/time/EpochUTC.ts +++ b/src/time/EpochUTC.ts @@ -21,6 +21,7 @@ * SOFTWARE. */ +import { Seconds } from '../main'; import { DEG2RAD, MS_PER_DAY, RAD2DEG, secondsPerWeek, TAU } from '../utils/constants'; import { evalPoly } from '../utils/functions'; import { DataHandler } from './../data/DataHandler'; @@ -67,11 +68,11 @@ export class EpochUTC extends Epoch { return new EpochUTC(new Date(dts).getTime() / 1000); } - static fromJ2000TTSeconds(seconds: number): EpochUTC { + static fromJ2000TTSeconds(seconds: Seconds): EpochUTC { const tInit = new EpochUTC(seconds + 946728000); const ls = DataHandler.getInstance().getLeapSeconds(tInit.toJulianDate()); - return tInit.roll(-32.184 - ls); + return tInit.roll(-32.184 - ls as Seconds); } static fromDefinitiveString(definitiveString: string): EpochUTC { @@ -87,7 +88,7 @@ export class EpochUTC extends Epoch { return new EpochUTC(dts / 1000); } - roll(seconds: number): EpochUTC { + roll(seconds: Seconds): EpochUTC { return new EpochUTC(this.posix + seconds); } @@ -121,7 +122,7 @@ export class EpochUTC extends Epoch { toGPS(): EpochGPS { const referenceTime = EpochUTC.fromDateTimeString('1980-01-06T00:00:00.000Z'); const ls = DataHandler.getInstance().getLeapSeconds(this.toJulianDate()); - const delta = this.roll(ls - EpochGPS.offset).difference(referenceTime); + const delta = this.roll(ls - EpochGPS.offset as Seconds).difference(referenceTime); const week = delta / secondsPerWeek; const weekFloor = Math.floor(week); const seconds = (week - weekFloor) * secondsPerWeek; diff --git a/tsconfig.base.json b/tsconfig.base.json index 37b336f..42c59b8 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -7,8 +7,6 @@ "module": "es6", "lib": ["esnext"], "declaration": true, - // "noImplicitAny": true, - // "removeComments": true, "baseUrl": ".", "allowJs": true, "experimentalDecorators": true, @@ -17,7 +15,6 @@ "listFiles": true, "newLine": "LF", "skipLibCheck": true, - // "noEmitOnError": true, "types": ["jest", "node"], "moduleResolution": "Node", "esModuleInterop": true diff --git a/tsconfig.json b/tsconfig.json index a874b52..750919a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,4 @@ }, "include": ["./src/**/*.ts", "./test/**/*.ts"], "filesGlob": ["./src/**/*.ts", "./test/**/*.ts"], - "ignorePatterns": ["./src/sgp4/asc/**/*.ts"], - "exclude": ["./src/sgp4/asc/assembly/index.ts"] }