CosmosTime
Time scales, calendars and the simulation clock. Depends on CosmosCore and CosmosMath.
The time argument of the application is Instant (TDB seconds past J2000.0, the SPICE "ET"); this module is the
only place where UTC, TAI, TT, UT1, Julian dates and calendar dates are produced or consumed.
What is implemented
| File | Main API |
|---|---|
TimeSystem.swift |
TimeSystem (.standard), TimeScale, UT1Estimate, UT1Source, TimeValidity, TimeWarning |
LeapSeconds.swift |
LeapSecondTable (.bundled, init(lskText:sourceName:), deltaAT(mjd:), dayLength(mjd:), tdbMinusTT(tdbSeconds:)) |
DeltaT.swift |
DeltaTModel.deltaT(year:), EarthOrientationTable (init(finals2000A:), .bundledIfPresent) |
Calendar.swift |
CalendarSystem (gregorian / julian / mixed), CalendarDate, CivilDateTime, JulianDate (two-part), Weekday, CalendarMath |
ISO8601.swift |
ISO8601.parse, format, dateString, shifted, offsetString |
SimulationClock.swift |
CosmosClock (implements SimulationClock), ClockState, ClockStep, ObservationTimeMode, DisplayTimeSetting, ClockSnapshot |
TimeSystem key calls: instant(civil:in:calendar:), instant(utcYear:month:day:hour:minute:second:),
instant(iso8601:in:), instant(julianDate:in:), instant(secondsPastJ2000:in:), instant(julianEpoch:),
instant(date:), now(); and the inverse civil(_:in:calendar:), iso8601(_:in:fractionDigits:calendar:utcOffsetMinutes:),
julianDate(_:in:), mjd(_:in:), secondsPastJ2000(_:in:), julianEpoch(_:), date(_:), weekday(_:in:);
plus ttSeconds, taiSeconds, tdbMinusTT, julianCenturiesTT, deltaAT, ut1(_:), deltaT(_:), validity(_:).
Models, data and references
TAI, TT, TDB
- TT = TAI + 32.184 s (exact;
DELTET/DELTA_T_Aof the kernel). - TDB − TT = K·sin(E), E = M + EB·sin(M), M = M₀ + M₁·t with the constants of the leapseconds kernel
(K = 1.657e-3 s, EB = 1.671e-2, M₀ = 6.239996 rad, M₁ = 1.99096871e-7 rad/s) — the same formula SPICE uses, so an
Instantbuilt here is the ET that SPICE would produce. TT → TDB iterates the formula three times. Accuracy of the formula: about 30 µs (NAIF Time Required Reading). Measured here: −8.7 µs against the full serieseraDtdbat one date (ERFAt_dtdb), and at most 20.8 µs against the TDB − UT column of JPL Horizons at five dates in 2024.
UTC and leap seconds
- Table:
naif0012.tls, NAIF generic leapseconds kernel, bundled unmodified inSources/Resourcesand parsed at runtime (LeapSecondTable.bundled). URL https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls, retrieved 2026-11-24, SHA-256678e32bdb5a744117a467cd9601cd6b373f0e9bc9bbde1371d5eee39600a039b. 28 steps, 1972-01-01 (TAI − UTC = 10 s) to 2017-01-01 (37 s). Refresh:DataPipeline/time/fetch_naif_lsk.sh. To do by the lead: list this file inDATA_SOURCES.md. - During a leap second the UTC label is
23:59:60.xof the day that ends (accepted on input, produced on output, rounded correctly byiso8601). Second 60 on any other day or in any other scale throwsinvalidInput. UTC Julian dates follow the SOFA "quasi-JD" convention (the leap-second day is 86401 s long, fraction < 1).secondsPastJ2000(_:in: .utc)is the SPICE-style count that ignores leap seconds (ambiguous inside one). - Before 1972-01-01 UTC in its present form did not exist and the 1960–1971 "rubber second" UTC is not
modelled. Civil time labelled UTC before 1972 is UT1 obtained with the ΔT model;
validityreports.utcBefore1972IsUniversalTimeanddeltaATreturns nil. Consequence: at 1972-01-01 the two regimes do not join exactly (ΔT model 42.25 s vs TT − UTC = 42.184 s), so labels within ≈0.07 s of that midnight are not invertible. (SPICE instead extends TAI − UTC = 9 s backwards; JPL Horizons uses UT1 before 1962.) - After the last tabulated leap second TAI − UTC keeps its last value (37 s). Future leap seconds are
unknown. IERS Bulletin C 72 (6 July 2026) rules out a leap second at the end of December 2026, so the offset is
established through 2027-06-30 (
TimeSystem.bulletinC72ConfirmedThroughMJD); later dates carry.leapSecondsUnknownAfter("2027-06-30"). Only the UTC label is uncertain there — TDB/TT/TAI are unaffected.
UT1 and ΔT
ut1(_:) returns the UT1 reading, ΔT = TT − UT1, the source and the status:
EarthOrientationTable— daily UT1 − UTC of an IERS Rapid Service/Prediction Center (USNO)finals2000Afile (Bulletin A column), linearly interpolated as UT1 − TAI so that it is continuous across leap seconds. Source.iersObserved(statusobserved) or.iersPrediction(statusestimated). No table is bundled: no explicit redistribution statement was found next to the data files (https://datacenter.iers.org/data/9/finals2000A.all, https://maia.usno.navy.mil/ser7/finals2000A.all), so the file is optional data.DataPipeline/time/fetch_iers_finals2000A.sh <file>downloads it (3.8 MB, refreshed weekly); pass it withTimeSystem(earthOrientation: try EarthOrientationTable(finals2000A: text)), or drop it inSources/Resources/finals2000A.allonce the terms are cleared (EarthOrientationTable.bundledIfPresentpicks it up).DeltaTModel— Espenak & Meeus polynomial expressions (NASA/TP-2006-214141; https://eclipse.gsfc.nasa.gov/SEcat5/deltatpoly.html), source.deltaTModel, statusestimated. The argument is a continuous Julian year instead of the mid-month year of the source; the Canon-specific lunar correction is not applied. Defined for −1999…+3000; outside, the long-term parabola is evaluated and.deltaTOutsideModelRangeis raised.
Measured weakness of the default (no table): at 2024-06-15 the model gives ΔT = 74.14 s, IERS gives 69.20 s — the model is 4.94 s high, i.e. the Earth-rotation angle is off by ≈74″ (local sidereal time off by up to 5.3 s in the Horizons comparison of CosmosCoordinates). Precise topocentric work needs the table. When a table is loaded there is a step of that size where the table ends and the model takes over.
Calendars, Julian dates, epochs
- Proleptic Gregorian, proleptic Julian, and
mixed(Julian to 1582-10-04, Gregorian from 1582-10-15; the ten skipped dates are invalid). Astronomical year numbering (year 0 = 1 BC). Integer day-number algorithms valid for any year.JulianDateis two-part (day + fraction) to keep sub-microsecond resolution. - Julian epoch
J = 2000 + (JD_TT − 2451545)/365.25(julianEpoch,instant(julianEpoch:)). - ISO 8601 extended format only (
[±]YYYY-MM-DD[Thh:mm[:ss[.f]]][Z|±hh[:mm]]); no basic format, week or ordinal dates.
Simulation clock
CosmosClock (thread-safe, Synchronization.Mutex) wraps the pure value type ClockState:
play, pause, togglePlay, reverse, setSpeed, setRate, faster/slower (powers of ten, 10⁻³…10¹² s/s),
step(_:count:) (exact SI steps: second … Julian century, sidereal day, arbitrary seconds), jump(to:),
jump(toCivil:), returnToNow().
Three separate concepts:
- simulation time —
now/simulationTime: theInstantthe universe is evaluated at; - observation time —
observationTime, derived throughobservationMode(.followsSimulation,.fixed(Instant),.offset(seconds)); - display time —
display: DisplayTimeSetting(scale, calendar, UTC offset, digits) → text; never changes the instant.
snapshot() returns all of it atomically with validity: TimeValidity, so the interface can show the warnings
(UTC undefined, leap seconds unknown, UT1 from the long-term model, ΔT outside its range) instead of digits the
models do not support. The wall-clock and real-time sources are injectable (deterministic tests).
Validation and tolerances (tests: Packages/CosmosTime/Tests, 32 tests)
| Check | Reference | Tolerance | Measured / why |
|---|---|---|---|
| UTC → TDB, TT, TAI, TDB − UTC, JD (23 dates 1972–2040, 8 inside leap seconds) | CSPICE N0067 str2et, unitim, deltet with naif0012.tls (spice_time_reference.json) |
3e-7 s | worst 3.6e-10 s; the tolerance is 2.5 ulp of a Double at 9e8 s |
| TDB → UTC text (11 instants, 4 inside leap seconds) | CSPICE et2utc ISOC, 6 decimals |
exact string | identical |
| TAI − UTC | ERFA t_dat (32, 33, 37 s) |
exact | |
| quasi-JD UTC ↔ TAI, leap-second JD | ERFA t_utctai, t_taiutc, t_dtf2d |
1e-11 d, 1e-6 d | ERFA's own tolerances (1e-12 d relaxed to 1e-11: one Double JD fraction) |
| TDB − TT | ERFA t_dtdb |
40 µs | −8.7 µs measured; formula is a one-term approximation |
| calendar | ERFA t_cal2jd, t_jd2cal, t_epj; reform dates; JDN 0; MJD 0 |
exact / 1e-12 | |
| calendar round trip | 650 000 days per calendar, 6903 BC – AD 5500 | exact | |
| ΔT polynomials | values quoted on the NASA page (93 s at 2050, 17203.7 s at −500, segment constants) | 0.05 s / exact | junction steps ≤ 0.25 s measured |
| UT1 − UTC from table | rows of finals2000A (2024-01-01, 2024-06-15; 2016-12-31 / 2017-01-01 across the leap second) |
1e-7 s / 1e-6 s | UT1 continuous through the leap second |
| ΔT model vs IERS, 2024-06-15 | IERS table | < 10 s (sanity bound) | +4.94 s |
| text round trip (400 instants ± 950 yr, 5 scales, 6 decimals) | property | 5e-5 s | UT1/pre-1972 path iterates the ΔT model |
| leap-second confirmation date | IERS Bulletin C 72 text | exact | |
| clock | deterministic state machine | exact |
Fixtures (with URLs and dates) are described in Packages/CosmosTime/Tests/Fixtures/README.txt; the SPICE
fixture is regenerated by DataPipeline/time/make_spice_fixtures.py.
Known limits
Instantis a single Double: resolution 1.2e-7 s at ±30 years from J2000, 1e-6 s at ±250 years, ≈ 1e-5 s at ±2000 years.- TDB − TT is the LSK approximation (≈30 µs); no topocentric or planetary terms.
- UTC before 1972 is UT1 (see policy); 1960–1971 UTC is not reproduced. The 1972-01-01 junction is not exactly invertible.
- UT1 without an Earth-orientation table is a long-term model, several seconds off at present.
- The Earth-orientation table gives UT1 − UTC only (no polar motion, no dX/dY), with linear daily interpolation (sub-daily tidal terms, < 1 ms, ignored).
- POSIX time (
Date) cannot represent a leap second;instant(date:)is ambiguous by up to 1 s during one. ClockStepvalues are fixed SI durations, not calendar steps ("one month later" is not provided).- The bundled kernel and
bulletinC72ConfirmedThroughMJDmust be refreshed when the IERS announces a leap second or publishes a new Bulletin C (every six months).