Skip to content

Commit

Permalink
refactor: 🏷️ add more typing for Seconds in Epoch calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 15, 2024
1 parent 429c257 commit 0419a86
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/body/Sun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
RAD2DEG,
RaDec,
Radians,
Seconds,
SunTime,
TAU,
Vector3D,
Expand Down Expand Up @@ -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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/coordinate/Tle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/time/EpochGPS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* SOFTWARE.
*/

import { Seconds } from '../main';
import { DataHandler } from '../data/DataHandler';
import { secondsPerWeek } from '../utils/constants';
import type { EpochUTC } from './EpochUTC';
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
}
9 changes: 5 additions & 4 deletions src/time/EpochUTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"module": "es6",
"lib": ["esnext"],
"declaration": true,
// "noImplicitAny": true,
// "removeComments": true,
"baseUrl": ".",
"allowJs": true,
"experimentalDecorators": true,
Expand All @@ -17,7 +15,6 @@
"listFiles": true,
"newLine": "LF",
"skipLibCheck": true,
// "noEmitOnError": true,
"types": ["jest", "node"],
"moduleResolution": "Node",
"esModuleInterop": true
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}

0 comments on commit 0419a86

Please sign in to comment.