Skip to main content

deep_time/
constants.rs

1use crate::{Real, TSpan};
2
3/// Fixed-length second equivalents for ISO 8601 calendar units (Y, M, W, D).
4///
5/// These constants deliberately use the **Julian year** convention (exactly
6/// 365.25 days per year) rather than the slightly more precise Gregorian
7/// average (365.2425 days). This is the traditional astronomical standard
8/// used by Julian Day (JD) and Modified Julian Date (MJD) systems, and it
9/// matches the `NS_PER_YEAR` / `NS_PER_MONTH` constants.
10///
11/// They exist so that years/months/weeks/days can be converted to a
12/// **fixed number of seconds**.
13/// The resulting `Span` then contains only fixed time units (hours,
14/// minutes, seconds, nanoseconds) and no longer requires a reference
15/// date for `.total()` conversions.
16pub(crate) const SEC_PER_YEAR: i128 = 31_557_600; // 365.25 days × 86_400
17pub(crate) const SEC_PER_MONTH: i128 = 2_629_800; // 30.4375 days × 86_400
18pub(crate) const SEC_PER_DAY: i128 = 86_400;
19
20/// Exactly 86,400 seconds in one standard Earth day  
21/// (24 hours × 60 minutes × 60 seconds).
22pub const SEC_PER_DAY_F: Real = 86_400.0;
23pub const SEC_PER_DAYI64: i64 = 86_400;
24pub(crate) const SEC_PER_DAYI128: i128 = 86_400;
25
26/// Seconds in one GPS week (exactly 7 days).
27pub(crate) const SEC_PER_WEEK: i64 = 7 * SEC_PER_DAYI64;
28/// Attoseconds in one GPS week.
29pub(crate) const ATTOS_PER_WEEK: i128 = SEC_PER_WEEK as i128 * ATTOS_PER_SEC_I128;
30pub const ATTOS_PER_DAY: i128 = SEC_PER_DAYI128 * ATTOS_PER_SEC_I128;
31pub const ATTOS_PER_HALF_DAY: i128 = ATTOS_PER_DAY / 2;
32pub const ATTOS_PER_HALF_DAYU: u128 = ATTOS_PER_HALF_DAY as u128;
33
34/// Solar gravitational parameter GM☉ in m³ s⁻²  
35/// (exact nominal value from IAU 2015 Resolution B3)
36pub const GM_SUN: Real = 1.3271244e20;
37
38/// Speed of light in m/s (exact SI definition)
39pub const C: Real = 299792458.0;
40
41/// Speed of light squared (c²) in m² s⁻².  
42pub const C_SQUARED: Real = C * C;
43
44/// GM☉ / c³ in seconds (exact from `GM_SUN` and `C` — used in Shapiro delay)
45pub const GM_SUN_OVER_C3: Real = GM_SUN / (C * C_SQUARED);
46
47/// 2GM☉ / c³ — the standard prefactor in the one-way Shapiro delay formula
48pub const TWO_GM_SUN_OVER_C3: Real = 2.0 * GM_SUN_OVER_C3;
49
50/// Attoseconds per second.
51pub const ATTOS_PER_SEC: u64 = 1_000_000_000_000_000_000;
52pub const ATTOS_PER_SECF: Real = f!(1_000_000_000_000_000_000.0);
53pub const ATTOS_PER_SEC_I128: i128 = ATTOS_PER_SEC as i128;
54pub const ATTOS_PER_SEC_U128: u128 = ATTOS_PER_SEC as u128;
55
56/// Attoseconds per millisecond (10⁻³ s).
57pub const ATTOS_PER_MS: u64 = 1_000_000_000_000_000;
58/// Attoseconds per microsecond (10⁻⁶ s).
59pub const ATTOS_PER_US: u64 = 1_000_000_000_000;
60/// Attoseconds per nanosecond (10⁻⁹ s).
61pub const ATTOS_PER_NS: u64 = 1_000_000_000;
62/// Attoseconds per picosecond (10⁻¹² s).
63pub const ATTOS_PER_PS: u64 = 1_000_000;
64/// Attoseconds per femtosecond (10⁻¹⁵ s).
65pub const ATTOS_PER_FS: u64 = 1_000;
66/// Attoseconds per millisecond (10⁻³ s).
67pub const ATTOS_PER_MS_I128: i128 = ATTOS_PER_MS as i128;
68/// Attoseconds per microsecond (10⁻⁶ s).
69pub const ATTOS_PER_US_I128: i128 = ATTOS_PER_US as i128;
70/// Attoseconds per nanosecond (10⁻⁹ s).
71pub const ATTOS_PER_NS_I128: i128 = ATTOS_PER_NS as i128;
72/// Attoseconds per picosecond (10⁻¹² s).
73pub const ATTOS_PER_PS_I128: i128 = ATTOS_PER_PS as i128;
74/// Attoseconds per femtosecond (10⁻¹⁵ s).
75pub const ATTOS_PER_FS_I128: i128 = ATTOS_PER_FS as i128;
76
77/// TT = TAI + exactly 32.184 s
78pub(crate) const TT_TAI_OFFSET_SEC: i64 = 32;
79pub(crate) const TT_TAI_OFFSET_SUBSEC: u64 = 184_000_000_000_000_000; // 0.184 × 10¹⁸
80
81/// Helper that returns the exact TT–TAI offset as a `TSpan`.
82pub const TT_TAI_OFFSET_SPAN: TSpan = TSpan::new(TT_TAI_OFFSET_SEC, TT_TAI_OFFSET_SUBSEC);
83
84// J2000.0 = 2000-01-01 12:00:00 TT → 100 Julian years = exactly 3_155_760_000 s
85pub(crate) const J2000_SEC_PER_CENTURY: Real = 3_155_760_000.0;
86
87/// Julian Date of the J2000.0 epoch in Terrestrial Time (TT).
88pub const J2000_JD_TT: i64 = 2_451_545;
89/// MJD 40587.0 exactly = 1970-01-01 00:00:00 UTC
90pub const MJD_1970: i64 = 40_587;
91/// Number of TAI seconds backwards from noon 2000-01-01 to midnight 1972-01-01
92pub const TAI_SEC_AT_1972: i64 = -883_655_990;
93
94/// Seconds from the Unix epoch (1970-01-01 00:00:00 UTC) to J2000.0 noon
95/// (2000-01-01 12:00:00 UTC).
96pub(crate) const UNIX_EPOCH_TO_J2000_NOON_UTC: i64 = 946_728_000;
97
98pub(crate) const FS_PER_SEC: i128 = 1_000_000_000_000_000;
99pub(crate) const PS_PER_SEC: i128 = 1_000_000_000_000;
100pub(crate) const NS_PER_SEC: i128 = 1_000_000_000;
101pub(crate) const US_PER_SEC: i128 = 1_000_000;
102pub(crate) const MS_PER_SEC: i128 = 1_000;
103
104// JD 2440587.5 = 1970-01-01 00:00:00 UTC (the .5 is handled by ATTOS_PER_HALF_DAY)
105pub(crate) const JD_EPOCH_DAYS: i128 = 2_440_587;
106
107pub const PLANCK_LENGTH: Real = 1.616255e-35; // meters (standard value)
108pub const PLANCK_LENGTH_4: Real = PLANCK_LENGTH * PLANCK_LENGTH * PLANCK_LENGTH * PLANCK_LENGTH;
109
110/// L_G = 6.969290134 × 10^{-10} (exact IAU) as fixed-point fraction.
111pub(crate) const LG_NUM: i128 = 6_969_290_134;
112pub(crate) const LG_DEN: i128 = 10_000_000_000_000_000_000; // 10^19
113
114/// L_B = 1.550519768 × 10^{-8} (exact IAU) as fixed-point fraction.
115pub(crate) const LB_NUM: i128 = 1_550_519_768;
116pub(crate) const LB_DEN: i128 = 100_000_000_000_000_000; // 10^17
117
118/// TCG/TCB reference epoch (JD 2443144.5003725) broken into integer parts for exact math.
119pub(crate) const TCG_TCB_REF_JD_INT: i64 = 2_443_144;
120pub(crate) const TCG_TCB_REF_TOD_SEC: i64 = 43_232; // 0.5003725 * 86400 = 43232.184
121pub(crate) const TCG_TCB_REF_TOD_SUBSEC: u64 = TT_TAI_OFFSET_SUBSEC;
122
123/// TDB₀ = −65.5 µs expressed in attoseconds (exact).
124pub(crate) const TDB0_ATTOS: i128 = -65_500_000_000_000;
125
126/// L_M = 6.48378 × 10^{-10} (exact secular rate from Ashby & Patla 2024 NIST for LTC ↔ TT)
127/// as fixed-point fraction.
128pub(crate) const LM_NUM: i128 = 648_378;
129pub(crate) const LM_DEN: i128 = 1_000_000_000_000_000; // 10^15
130
131/// Exact mean length of one Martian sol in Earth seconds (NASA GISS / AM2000)
132pub const MARS_SOL_LENGTH_SEC: Real = 88775.244;
133
134/// Mars MSD reference epoch (JD 2405522.0028779 TT) broken into integer parts for exact math.
135pub(crate) const MARS_MSD_REF_JD_INT: i64 = 2_405_522;
136pub(crate) const MARS_MSD_REF_TOD_SEC: i64 = 248;
137pub(crate) const MARS_MSD_REF_TOD_SUBSEC: u64 = 650_560_000_000_000_000;
138
139/// Martian mean sol length in attoseconds (88775.244 s × 10¹⁸).
140pub const MARS_SOL_ATTOS: i128 = 88_775_244_000_000_000_000_000;
141
142/// Precomputed numerical values of the Mars reference epoch on the TT scale (seconds since J2000).
143pub(crate) const MARS_REF_TT: TSpan = TSpan::new(-3_976_386_952, 650_560_000_000_000_000);
144
145pub(crate) const WEEKDAYS_FULL: [&[u8]; 7] = [
146    b"Sunday",
147    b"Monday",
148    b"Tuesday",
149    b"Wednesday",
150    b"Thursday",
151    b"Friday",
152    b"Saturday",
153];
154pub(crate) const WEEKDAYS_ABBR: [&[u8]; 7] =
155    [b"Sun", b"Mon", b"Tue", b"Wed", b"Thu", b"Fri", b"Sat"];
156pub(crate) const MONTHS_FULL: [&[u8]; 12] = [
157    b"January",
158    b"February",
159    b"March",
160    b"April",
161    b"May",
162    b"June",
163    b"July",
164    b"August",
165    b"September",
166    b"October",
167    b"November",
168    b"December",
169];
170pub(crate) const MONTHS_ABBR: [&[u8]; 12] = [
171    b"Jan", b"Feb", b"Mar", b"Apr", b"May", b"Jun", b"Jul", b"Aug", b"Sep", b"Oct", b"Nov", b"Dec",
172];
173
174pub const STRFTIME_SIZE: usize = 512;