SPB Git

Repository Public

CosmosTime.md 10.9 KB 139 lines markdown

1<!--2ORIX Cosmos3File: Documentation/modules/CosmosTime.md4Description: What CosmosTime implements (time scales, leap seconds, Delta T, calendars, ISO 8601, simulation clock), its policies, data sources, accuracy measured in the tests, and known limits.5Author: Simon-Pierre Boucher6Contact: contact@spboucher.ai7-->8# CosmosTime910Time scales, calendars and the simulation clock. Depends on `CosmosCore` and `CosmosMath`.11The time argument of the application is `Instant` (TDB seconds past J2000.0, the SPICE "ET"); this module is the12only place where UTC, TAI, TT, UT1, Julian dates and calendar dates are produced or consumed.1314## What is implemented1516| File | Main API |17|---|---|18| `TimeSystem.swift` | `TimeSystem` (`.standard`), `TimeScale`, `UT1Estimate`, `UT1Source`, `TimeValidity`, `TimeWarning` |19| `LeapSeconds.swift` | `LeapSecondTable` (`.bundled`, `init(lskText:sourceName:)`, `deltaAT(mjd:)`, `dayLength(mjd:)`, `tdbMinusTT(tdbSeconds:)`) |20| `DeltaT.swift` | `DeltaTModel.deltaT(year:)`, `EarthOrientationTable` (`init(finals2000A:)`, `.bundledIfPresent`) |21| `Calendar.swift` | `CalendarSystem` (gregorian / julian / mixed), `CalendarDate`, `CivilDateTime`, `JulianDate` (two-part), `Weekday`, `CalendarMath` |22| `ISO8601.swift` | `ISO8601.parse`, `format`, `dateString`, `shifted`, `offsetString` |23| `SimulationClock.swift` | `CosmosClock` (implements `SimulationClock`), `ClockState`, `ClockStep`, `ObservationTimeMode`, `DisplayTimeSetting`, `ClockSnapshot` |2425`TimeSystem` key calls: `instant(civil:in:calendar:)`, `instant(utcYear:month:day:hour:minute:second:)`,26`instant(iso8601:in:)`, `instant(julianDate:in:)`, `instant(secondsPastJ2000:in:)`, `instant(julianEpoch:)`,27`instant(date:)`, `now()`; and the inverse `civil(_:in:calendar:)`, `iso8601(_:in:fractionDigits:calendar:utcOffsetMinutes:)`,28`julianDate(_:in:)`, `mjd(_:in:)`, `secondsPastJ2000(_:in:)`, `julianEpoch(_:)`, `date(_:)`, `weekday(_:in:)`;29plus `ttSeconds`, `taiSeconds`, `tdbMinusTT`, `julianCenturiesTT`, `deltaAT`, `ut1(_:)`, `deltaT(_:)`, `validity(_:)`.3031## Models, data and references3233### TAI, TT, TDB34- TT = TAI + 32.184 s (exact; `DELTET/DELTA_T_A` of the kernel).35- TDB − TT = K·sin(E), E = M + EB·sin(M), M = M₀ + M₁·t with the constants of the leapseconds kernel36  (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 an37  `Instant` built here is the ET that SPICE would produce. TT → TDB iterates the formula three times.38  Accuracy of the formula: about 30 µs (NAIF *Time Required Reading*). Measured here: −8.7 µs against the full39  series `eraDtdb` at one date (ERFA `t_dtdb`), and at most 20.8 µs against the TDB − UT column of JPL Horizons at40  five dates in 2024.4142### UTC and leap seconds43- Table: **`naif0012.tls`**, NAIF generic leapseconds kernel, bundled unmodified in `Sources/Resources` and parsed at44  runtime (`LeapSecondTable.bundled`). URL https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls,45  retrieved 2026-11-24, SHA-256 `678e32bdb5a744117a467cd9601cd6b373f0e9bc9bbde1371d5eee39600a039b`.46  28 steps, 1972-01-01 (TAI − UTC = 10 s) to 2017-01-01 (37 s). Refresh: `DataPipeline/time/fetch_naif_lsk.sh`.47  **To do by the lead:** list this file in `DATA_SOURCES.md`.48- **During a leap second** the UTC label is `23:59:60.x` of the day that ends (accepted on input, produced on49  output, rounded correctly by `iso8601`). Second 60 on any other day or in any other scale throws `invalidInput`.50  UTC Julian dates follow the SOFA "quasi-JD" convention (the leap-second day is 86401 s long, fraction < 1).51  `secondsPastJ2000(_:in: .utc)` is the SPICE-style count that ignores leap seconds (ambiguous inside one).52- **Before 1972-01-01** UTC in its present form did not exist and the 1960–1971 "rubber second" UTC is *not*53  modelled. Civil time labelled UTC before 1972 is **UT1 obtained with the ΔT model**; `validity` reports54  `.utcBefore1972IsUniversalTime` and `deltaAT` returns nil. Consequence: at 1972-01-01 the two regimes do not join55  exactly (ΔT model 42.25 s vs TT − UTC = 42.184 s), so labels within ≈0.07 s of that midnight are not invertible.56  (SPICE instead extends TAI − UTC = 9 s backwards; JPL Horizons uses UT1 before 1962.)57- **After the last tabulated leap second** TAI − UTC keeps its last value (37 s). **Future leap seconds are58  unknown.** IERS Bulletin C 72 (6 July 2026) rules out a leap second at the end of December 2026, so the offset is59  established through 2027-06-30 (`TimeSystem.bulletinC72ConfirmedThroughMJD`); later dates carry60  `.leapSecondsUnknownAfter("2027-06-30")`. Only the UTC *label* is uncertain there — TDB/TT/TAI are unaffected.6162### UT1 and ΔT63`ut1(_:)` returns the UT1 reading, ΔT = TT − UT1, the **source** and the **status**:64651. `EarthOrientationTable` — daily UT1 − UTC of an IERS Rapid Service/Prediction Center (USNO) `finals2000A` file66   (Bulletin A column), linearly interpolated as UT1 − TAI so that it is continuous across leap seconds.67   Source `.iersObserved` (status `observed`) or `.iersPrediction` (status `estimated`).68   **No table is bundled**: no explicit redistribution statement was found next to the data files69   (https://datacenter.iers.org/data/9/finals2000A.all, https://maia.usno.navy.mil/ser7/finals2000A.all), so the file70   is optional data. `DataPipeline/time/fetch_iers_finals2000A.sh <file>` downloads it (3.8 MB, refreshed weekly);71   pass it with `TimeSystem(earthOrientation: try EarthOrientationTable(finals2000A: text))`, or drop it in72   `Sources/Resources/finals2000A.all` once the terms are cleared (`EarthOrientationTable.bundledIfPresent` picks it up).732. `DeltaTModel` — Espenak & Meeus polynomial expressions (NASA/TP-2006-214141;74   https://eclipse.gsfc.nasa.gov/SEcat5/deltatpoly.html), source `.deltaTModel`, status `estimated`. The argument75   is a continuous Julian year instead of the mid-month year of the source; the Canon-specific lunar correction76   is not applied. Defined for −1999…+3000; outside, the long-term parabola is evaluated and77   `.deltaTOutsideModelRange` is raised.7879**Measured weakness of the default (no table):** at 2024-06-15 the model gives ΔT = 74.14 s, IERS gives 69.20 s80— the model is **4.94 s high**, i.e. the Earth-rotation angle is off by ≈74″ (local sidereal time off by up to815.3 s in the Horizons comparison of CosmosCoordinates). Precise topocentric work needs the table.82When a table is loaded there is a step of that size where the table ends and the model takes over.8384### Calendars, Julian dates, epochs85- Proleptic Gregorian, proleptic Julian, and `mixed` (Julian to 1582-10-04, Gregorian from 1582-10-15; the ten86  skipped dates are invalid). Astronomical year numbering (year 0 = 1 BC). Integer day-number algorithms valid for87  any year. `JulianDate` is two-part (day + fraction) to keep sub-microsecond resolution.88- Julian epoch `J = 2000 + (JD_TT − 2451545)/365.25` (`julianEpoch`, `instant(julianEpoch:)`).89- ISO 8601 extended format only (`[±]YYYY-MM-DD[Thh:mm[:ss[.f]]][Z|±hh[:mm]]`); no basic format, week or ordinal dates.9091### Simulation clock92`CosmosClock` (thread-safe, `Synchronization.Mutex`) wraps the pure value type `ClockState`:93`play`, `pause`, `togglePlay`, `reverse`, `setSpeed`, `setRate`, `faster`/`slower` (powers of ten, 10⁻³…10¹² s/s),94`step(_:count:)` (exact SI steps: second … Julian century, sidereal day, arbitrary seconds), `jump(to:)`,95`jump(toCivil:)`, `returnToNow()`.9697Three separate concepts:98- **simulation time** — `now` / `simulationTime`: the `Instant` the universe is evaluated at;99- **observation time** — `observationTime`, derived through `observationMode` (`.followsSimulation`, `.fixed(Instant)`, `.offset(seconds)`);100- **display time** — `display: DisplayTimeSetting` (scale, calendar, UTC offset, digits) → text; never changes the instant.101102`snapshot()` returns all of it atomically with `validity: TimeValidity`, so the interface can show the warnings103(UTC undefined, leap seconds unknown, UT1 from the long-term model, ΔT outside its range) instead of digits the104models do not support. The wall-clock and real-time sources are injectable (deterministic tests).105106## Validation and tolerances (tests: `Packages/CosmosTime/Tests`, 32 tests)107108| Check | Reference | Tolerance | Measured / why |109|---|---|---|---|110| 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 |111| TDB → UTC text (11 instants, 4 inside leap seconds) | CSPICE `et2utc` ISOC, 6 decimals | exact string | identical |112| TAI − UTC | ERFA `t_dat` (32, 33, 37 s) | exact | |113| 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) |114| TDB − TT | ERFA `t_dtdb` | 40 µs | −8.7 µs measured; formula is a one-term approximation |115| calendar | ERFA `t_cal2jd`, `t_jd2cal`, `t_epj`; reform dates; JDN 0; MJD 0 | exact / 1e-12 | |116| calendar round trip | 650 000 days per calendar, 6903 BC – AD 5500 | exact | |117| Δ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 |118| 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 |119| ΔT model vs IERS, 2024-06-15 | IERS table | < 10 s (sanity bound) | **+4.94 s** |120| text round trip (400 instants ± 950 yr, 5 scales, 6 decimals) | property | 5e-5 s | UT1/pre-1972 path iterates the ΔT model |121| leap-second confirmation date | IERS Bulletin C 72 text | exact | |122| clock | deterministic state machine | exact | |123124Fixtures (with URLs and dates) are described in `Packages/CosmosTime/Tests/Fixtures/README.txt`; the SPICE125fixture is regenerated by `DataPipeline/time/make_spice_fixtures.py`.126127## Known limits128129- `Instant` is 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.130- TDB − TT is the LSK approximation (≈30 µs); no topocentric or planetary terms.131- UTC before 1972 is UT1 (see policy); 1960–1971 UTC is not reproduced. The 1972-01-01 junction is not exactly invertible.132- UT1 without an Earth-orientation table is a long-term model, several seconds off at present.133- The Earth-orientation table gives UT1 − UTC only (no polar motion, no dX/dY), with linear daily interpolation134  (sub-daily tidal terms, < 1 ms, ignored).135- POSIX time (`Date`) cannot represent a leap second; `instant(date:)` is ambiguous by up to 1 s during one.136- `ClockStep` values are fixed SI durations, not calendar steps ("one month later" is not provided).137- The bundled kernel and `bulletinC72ConfirmedThroughMJD` must be refreshed when the IERS announces a leap second138  or publishes a new Bulletin C (every six months).139
Files main
Menu

Theme