UNPKG

ootk

Version:

Orbital Object Toolkit including Multiple Propagators, Initial Orbit Determination, and Maneuver Calculations.

109 lines 4.07 kB
/** * @author @thkruz Theodore Kruczek * @description Orbital Object ToolKit (ootk) is a collection of tools for working * with satellites and other orbital objects. * @license AGPL-3.0-or-later * @copyright (c) 2025 Kruczek Labs LLC * * Many of the classes are based off of the work of @david-rc-dayton and his * Pious Squid library (https://github.com/david-rc-dayton/pious_squid) which * is licensed under the MIT license. * * Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the * terms of the GNU Affero General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later version. * * Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License along with * Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>. */ import { secondsPerDay } from '../utils/constants.js'; // / Base class for [Epoch] data. export class Epoch { posix; /* * Create a new [Epoch] object given the number of seconds elapsed since the * [posix] epoch _(`1970-01-01T00:00:00.000`)_ in the [Epoch] time scale. */ constructor(posix) { this.posix = posix; if (posix < 0) { throw new Error('Epoch cannot be negative'); } } toString() { return this.toDateTime().toISOString(); } // / Convert this to an Excel spreadsheet string. toExcelString() { return this.toString().substring(0, 19); } // / Return the difference _(s)_ between this and another [epoch]/ difference(epoch) { return this.posix - epoch.posix; } // / Check if this has the same timestamp as the provided [epoch]. equals(epoch) { return this.posix === epoch.posix; } // / Convert to a [DateTime] object. toDateTime() { return new Date(this.posix * 1000); } toEpochYearAndDay() { const currentDateObj = this.toDateTime(); const epochYear = currentDateObj.getUTCFullYear().toString().slice(2, 4); const epochDay = this.getDayOfYear_(currentDateObj); const timeOfDay = (currentDateObj.getUTCHours() * 60 + currentDateObj.getUTCMinutes()) / 1440; const epochDayStr = (epochDay + timeOfDay).toFixed(8).padStart(12, '0'); return { epochYr: epochYear, epochDay: epochDayStr, }; } getDayOfYear_(date) { const dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; const mn = date.getUTCMonth(); const dn = date.getUTCDate(); let dayOfYear = dayCount[mn] + dn; if (mn > 1 && this.isLeapYear_(date)) { dayOfYear++; } return dayOfYear; } isLeapYear_(dateIn) { const year = dateIn.getUTCFullYear(); if ((year & 3) !== 0) { return false; } return year % 100 !== 0 || year % 400 === 0; } // / Convert to Julian date. toJulianDate() { return this.posix / secondsPerDay + 2440587.5; } // / Convert to Julian centuries. toJulianCenturies() { return (this.toJulianDate() - 2451545) / 36525; } // / Check if this is later than the [other] epoch. operatorGreaterThan(other) { return this.posix > other.posix; } // / Check if this is later or the same as the [other] epoch. operatorGreaterThanOrEqual(other) { return this.posix >= other.posix; } // / Check if this is earlier than the [other] epoch. operatorLessThan(other) { return this.posix < other.posix; } // / Check if this is earlier or the same as the [other] epoch. operatorLessThanOrEqual(other) { return this.posix <= other.posix; } } //# sourceMappingURL=Epoch.js.map