1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! Time scale conversions between astronomical time systems.
//!
//! This module provides traits and implementations for converting between the eight
//! major astronomical time scales: GPS, TAI, TT, TCG, TCB, TDB, UT1, and UTC.
//!
//! # Time Scale Overview
//!
//! | Scale | Full Name | Basis | Primary Use |
//! |-------|-----------|-------|-------------|
//! | UTC | Coordinated Universal Time | Atomic + leap seconds | Civil timekeeping |
//! | TAI | International Atomic Time | Atomic clocks | Reference for other scales |
//! | TT | Terrestrial Time | TAI + 32.184s | Geocentric ephemerides |
//! | UT1 | Universal Time 1 | Earth rotation | Sidereal time, telescope pointing |
//! | GPS | GPS Time | Atomic (no leap seconds) | Satellite navigation |
//! | TCG | Geocentric Coordinate Time | Relativistic (Earth center) | Precise geocentric dynamics |
//! | TCB | Barycentric Coordinate Time | Relativistic (solar system) | Solar system dynamics |
//! | TDB | Barycentric Dynamical Time | TCB rescaled | Solar system ephemerides |
//!
//!
//! # Fixed vs Variable Offsets
//!
//! Some conversions use constant offsets:
//!
//! - **TAI <-> TT**: Fixed 32.184 seconds
//! - **TAI <-> GPS**: Fixed 19.0 seconds
//! - **TT <-> TCG**: Secular rate 6.969290134e-10 (IAU 2000)
//! - **TCG <-> TCB**: Secular rate 1.550519768e-8 (IAU 2006)
//!
//! Others require external data that changes over time:
//!
//! - **UTC <-> TAI**: Leap second table (currently 37 seconds as of 2017)
//! - **UT1 <-> TAI**: IERS Earth Orientation Parameters (changes daily)
//! - **UT1 <-> TT**: Delta-T from historical tables or predictions
//! - **TT <-> TDB**: Location-dependent, ~1.66ms annual oscillation
//!
//! # Trait Pattern
//!
//! Each target scale has a conversion trait:
//!
//! - [`ToTAI`]: Convert to International Atomic Time
//! - [`ToTT`]: Convert to Terrestrial Time
//! - [`ToGPS`]: Convert to GPS Time
//! - [`ToUTC`]: Convert to Coordinated Universal Time
//! - [`ToUT1`]: Convert to Universal Time 1
//! - [`ToTCG`]: Convert to Geocentric Coordinate Time
//!
//! Additional traits handle conversions requiring parameters:
//!
//! - [`ToUT1WithOffset`], [`ToTAIWithOffset`]: UT1 <-> TAI with IERS offset
//! - [`ToTTWithDeltaT`], [`ToUT1WithDeltaT`]: UT1 <-> TT with historical Delta-T
//! - [`ToTDB`], [`ToTTFromTDB`]: TT <-> TDB with observer location
//! - [`ToTCB`], [`ToTCGFromTCB`]: TCG <-> TCB relativistic conversions
//!
//! # Usage
//!
//! Simple fixed-offset conversions work directly:
//!
//! ```
//! use celestial_time::scales::{TAI, TT, GPS};
//! use celestial_time::scales::conversions::{ToTAI, ToTT};
//! use celestial_time::julian::JulianDate;
//!
//! let tai = TAI::from_julian_date(JulianDate::new(2451545.0, 0.0));
//! let tt = tai.to_tt().unwrap(); // TAI + 32.184s
//! ```
//!
//! Conversions requiring external data take parameters:
//!
//! ```
//! use celestial_time::scales::{TAI, UT1};
//! use celestial_time::scales::conversions::{ToUT1WithOffset, ToTAIWithOffset};
//! use celestial_time::julian::JulianDate;
//!
//! // UT1-TAI offset from IERS Bulletin A
//! let ut1_tai_offset = -37.0; // seconds
//!
//! let tai = TAI::from_julian_date(JulianDate::new(2451545.0, 0.0));
//! let ut1 = tai.to_ut1_with_offset(ut1_tai_offset).unwrap();
//! let back = ut1.to_tai_with_offset(ut1_tai_offset).unwrap();
//! ```
//!
//! # Precision Notes
//!
//! All conversions preserve precision by applying offsets to the smaller-magnitude
//! component of the two-part Julian Date. Round-trip conversions maintain
//! sub-nanosecond accuracy for fixed-offset scales.
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
use crate;
use crateTimeResult;
/// Convert a time scale to GPS Time.
///
/// GPS Time runs at the same rate as TAI but with a fixed offset of -19 seconds
/// (GPS = TAI - 19s). It does not include leap seconds, making it continuous
/// since its epoch of January 6, 1980.
///
/// Implemented for: GPS (identity), TAI
/// Convert a time scale to International Atomic Time (TAI).
///
/// TAI is the fundamental atomic time scale, maintained by a weighted average of
/// atomic clocks worldwide. It serves as the reference for most other time scales.
///
/// Implemented for: TAI (identity), UTC, TT, GPS, TCG
///
/// For UT1 → TAI, use [`ToTAIWithOffset`] which requires the IERS UT1-TAI offset.
/// Convert a time scale to Terrestrial Time (TT).
///
/// TT is the time scale for geocentric ephemerides and Earth-based observations.
/// It differs from TAI by exactly 32.184 seconds (TT = TAI + 32.184s), a value
/// chosen for continuity with the older ET (Ephemeris Time) scale.
///
/// Implemented for: TT (identity), TAI, TCG
///
/// For TDB → TT, use [`ToTTFromTDB`] which requires observer location.
/// For UT1 → TT, use [`ToTTWithDeltaT`] which requires Delta-T.
/// Convert a time scale to Geocentric Coordinate Time (TCG).
///
/// TCG is the proper time for a clock at the geocenter, accounting for
/// gravitational time dilation. It runs faster than TT by a rate of
/// approximately 6.969290134e-10 (about 22 ms/year).
///
/// Implemented for: TCG (identity), TT
///
/// For TCB → TCG, use [`ToTCGFromTCB`].
/// Convert a time scale to Coordinated Universal Time (UTC).
///
/// UTC is the basis for civil timekeeping. It tracks TAI but is adjusted by
/// leap seconds to stay within 0.9 seconds of UT1 (Earth rotation time).
/// Leap seconds are inserted (or theoretically removed) based on IERS
/// announcements.
///
/// Implemented for: UTC (identity), TAI, TT
///
/// Note: This conversion requires the leap second table in this crate,
/// which must be updated when new leap seconds are announced.
/// Convert a time scale to Universal Time 1 (UT1).
///
/// UT1 is tied to Earth's actual rotation angle. Unlike atomic time scales,
/// it varies unpredictably due to tidal friction, core-mantle coupling, and
/// atmospheric effects. The difference UT1-UTC (DUT1) is kept within 0.9s
/// by leap second adjustments.
///
/// Implemented for: UT1 (identity)
///
/// For TAI → UT1, use [`ToUT1WithOffset`] with the IERS UT1-TAI offset.
/// For TT → UT1, use [`ToUT1WithDeltaT`] with Delta-T.