Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

/*****************************************************************************************************************/

import { getJulianDate, getModifiedJulianDate } from './epoch'
import {
getInternationalAtomicTime,
getJulianDate,
getModifiedJulianDate,
getTerrestrialTime
} from './epoch'

import { LEAP_SECONDS } from './iers'

Expand Down Expand Up @@ -48,24 +53,12 @@ export class DateTime extends Date {
*
*/
getInternationalAtomicTime(): number {
const zero = new Date('1972-01-01T00:00:00.000+00:00').getTime()
// The International Atomic Time (TAI) is the time scale that combines the output of
// some 400 highly precise atomic clocks worldwide, and provides the exact speed of our
// clocks, which is essential for the accurate positioning of satellites and for many
// other applications.
let dtai = 0

const d = super.getTime()

// If the date is before the first leap second was added, return the date.
if (d < zero) return d

// Iterate backwards over the leap seconds table to find the current number of leap seconds.
dtai = applyDTAICorrectionToDateTime(d, zero)

// The difference between TAI and UTC is the number of leap seconds that have been
// added to the UTC time scale. This difference is known as DTAI.
return d + dtai * 1000
// other applications. The time scale itself is resolved by the epoch module, so that
// the leap seconds are applied in one place:
return getInternationalAtomicTime(this).getTime()
}

/**
Expand All @@ -83,11 +76,10 @@ export class DateTime extends Date {
*
*/
getTerrestrialTime(): number {
const tai = this.getInternationalAtomicTime()

// The difference between TAI and TT is the number of leap seconds that have been
// added to the UTC time scale. This difference is known as DTAI.
return tai + 32.184 * 1000
// The Terrestrial Time (TT) is the International Atomic Time (TAI) displaced by the
// constant 32.184 seconds. The time scale itself is resolved by the epoch module, so
// that the displacement is applied in one place:
return getTerrestrialTime(this).getTime()
}

/**
Expand Down