Skip to main content

deep_time/
consts.rs

1//! Fundamental constants for time-scale conversions,
2//! relativistic corrections, and astronomical calculations.
3
4use crate::{Dt, Real, Scale};
5
6/// The size limit for parsing and no-alloc formatting with
7/// the strtime related functionality.
8pub const STRTIME_SIZE: usize = 512;
9
10/// Number of decimal digits in one attosecond-precision second (`10¹⁸`).
11pub const ATTOS_DIGITS: usize = 18;
12
13/// Seconds in one Julian year (365.25 days × 86_400).
14pub const SEC_PER_YEAR: i128 = 31_557_600;
15
16/// Seconds in one average month (30.4375 days × 86_400).
17pub const SEC_PER_MONTH: i128 = 2_629_800;
18
19/// Seconds in one standard Earth day (24 × 60 × 60).
20pub const SEC_PER_DAY: i128 = 86_400;
21
22/// 86,400 seconds in one standard Earth day
23/// (24 hours × 60 minutes × 60 seconds).
24pub const SEC_PER_DAY_F: Real = 86_400.0;
25
26/// 86,400 seconds in one standard Earth day
27/// (24 hours × 60 minutes × 60 seconds).
28pub const SEC_PER_DAY_I64: i64 = 86_400;
29
30/// Seconds in one minute.
31pub const SEC_PER_MIN: i128 = 60;
32
33/// Seconds in one hour.
34pub const SEC_PER_HOUR: i128 = 3600;
35
36/// Attoseconds in one minute.
37pub const ATTOS_PER_MIN: i128 = SEC_PER_MIN * ATTOS_PER_SEC_I128;
38
39/// Attoseconds in one hour.
40pub const ATTOS_PER_HOUR: i128 = SEC_PER_HOUR * ATTOS_PER_SEC_I128;
41
42/// Seconds in one GPS week (7 days).
43pub const SEC_PER_WEEK: i64 = 7 * SEC_PER_DAY_I64;
44
45/// Attoseconds in one GPS week.
46pub const ATTOS_PER_WEEK: i128 = SEC_PER_WEEK as i128 * ATTOS_PER_SEC_I128;
47
48/// Attoseconds in one standard Earth day.
49pub const ATTOS_PER_DAY: i128 = SEC_PER_DAY * ATTOS_PER_SEC_I128;
50
51/// Attoseconds in half a standard Earth day (12 hours).
52pub const ATTOS_PER_HALF_DAY: i128 = ATTOS_PER_DAY / 2;
53
54/// Attoseconds in half a standard Earth day, as `u128`.
55pub const ATTOS_PER_HALF_DAY_U128: u128 = ATTOS_PER_HALF_DAY as u128;
56
57/// Attoseconds per second.
58pub const ATTOS_PER_SEC: u64 = 1_000_000_000_000_000_000;
59
60/// Attoseconds per second as a floating-point value.
61pub const ATTOS_PER_SECF: Real = f!(1_000_000_000_000_000_000.0);
62
63/// Attoseconds per second as `i128`.
64pub const ATTOS_PER_SEC_I128: i128 = ATTOS_PER_SEC as i128;
65
66/// Attoseconds per second as `u128`.
67pub const ATTOS_PER_SEC_U128: u128 = ATTOS_PER_SEC as u128;
68
69/// Attoseconds per nanosecond (10⁻⁹ s).
70pub const ATTOS_PER_NS: u64 = 1_000_000_000;
71
72/// Attoseconds per millisecond (10⁻³ s).
73pub const ATTOS_PER_MS_I128: i128 = 1_000_000_000_000_000;
74
75/// Attoseconds per microsecond (10⁻⁶ s).
76pub const ATTOS_PER_US_I128: i128 = 1_000_000_000_000;
77
78/// Attoseconds per nanosecond (10⁻⁹ s).
79pub const ATTOS_PER_NS_I128: i128 = ATTOS_PER_NS as i128;
80
81/// Attoseconds per picosecond (10⁻¹² s).
82pub const ATTOS_PER_PS_I128: i128 = 1_000_000;
83
84/// Attoseconds per femtosecond (10⁻¹⁵ s).
85pub const ATTOS_PER_FS_I128: i128 = 1_000;
86
87/// Fractional part of the TT–TAI offset (0.184 s) as attoseconds.
88pub const TT_TAI_OFFSET_ATTOS: u64 = 184_000_000_000_000_000; // 0.184 × 10¹⁸
89
90/// TT–TAI offset of 32.184 s as a [`Dt`].
91pub const TT_TAI_OFFSET: Dt = Dt::new(32_184_000_000_000_000_000i128, Scale::TAI, Scale::TAI);
92
93/// Julian Date of the J2000.0 epoch (JD 2451545.0).
94pub const JD_2000_2_451_545: i64 = 2_451_545;
95
96/// Julian Date of the J2000.0 epoch as `i128`.
97pub const JD_2000_2_451_545_I128: i128 = JD_2000_2_451_545 as i128;
98
99/// Julian Date of the J2000.0 epoch as a floating-point value.
100pub const JD_2000_2_451_545F: Real = f!(2_451_545.0);
101
102/// Modified Julian Date of the Unix epoch (MJD 40587.0 = 1970-01-01 00:00:00 UTC).
103pub const MJD_1970: i64 = 40_587;
104
105/// Number of TAI attoseconds from noon 2000-01-01 back to midnight 1972-01-01.
106pub const TAI_ATTOS_AT_1972: i128 = -883_655_990_000_000_000_000_000_000;
107
108/// TAI seconds from 1970-01-01 midnight to 2000-01-01 noon.
109pub const TAI_SECS_1970_MIDNIGHT_TO_2000_NOON: i64 = 946_728_000;
110
111/// Numerator of L_G = 6.969290134 × 10^{-10} (IAU) as a fixed-point fraction.
112pub(crate) const LG_NUM: i128 = 6_969_290_134;
113
114/// Denominator of L_G (10¹⁹) for the fixed-point fraction with [`LG_NUM`].
115pub(crate) const LG_DEN: i128 = 10_000_000_000_000_000_000; // 10^19
116
117/// Numerator of L_B = 1.550519768 × 10^{-8} (IAU) as a fixed-point fraction.
118pub(crate) const LB_NUM: i128 = 1_550_519_768;
119
120/// Denominator of L_B (10¹⁷) for the fixed-point fraction with [`LB_NUM`].
121pub(crate) const LB_DEN: i128 = 100_000_000_000_000_000; // 10^17
122
123/// Integer day part of the TCG/TCB reference epoch JD 2443144.5003725.
124pub(crate) const TCG_TCB_REF_JD_INT: i64 = 2_443_144;
125
126/// Time-of-day seconds of the TCG/TCB reference epoch
127/// (0.5003725 × 86400 = 43232.184, integer part).
128pub(crate) const TCG_TCB_REF_TOD_SEC: i64 = 43_232; // 0.5003725 * 86400 = 43232.184
129
130/// Sub-second attoseconds of the TCG/TCB reference epoch time-of-day
131/// (the 0.184 s fractional part, same as [`TT_TAI_OFFSET_ATTOS`]).
132pub(crate) const TCG_TCB_REF_TOD_SUBSEC: u64 = TT_TAI_OFFSET_ATTOS;
133
134/// Attoseconds since J2000.0 TT of the TCG/TCB reference epoch
135/// (JD 2443144.5003725 TT). Computed from the existing reference constants.
136pub(crate) const TCG_TCB_REF_ATTOS_SINCE_J2000: i128 = {
137    let days_since_j2000 = (TCG_TCB_REF_JD_INT - JD_2000_2_451_545) as i128;
138    let sec_part = days_since_j2000 * SEC_PER_DAY + (TCG_TCB_REF_TOD_SEC as i128);
139    sec_part * ATTOS_PER_SEC_I128 + (TCG_TCB_REF_TOD_SUBSEC as i128)
140};
141
142/// TDB₀ = −65.5 µs expressed in attoseconds.
143pub(crate) const TDB0_ATTOS: i128 = -65_500_000_000_000;
144
145/// Solar gravitational parameter GM☉ in m³ s⁻²
146/// (nominal value from IAU 2015 Resolution B3)
147#[cfg(feature = "physics")]
148pub const GM_SUN: Real = 1.3271244e20;
149
150/// Speed of light in m/s (SI definition)
151#[cfg(feature = "physics")]
152pub const C: Real = 299792458.0;
153
154/// Speed of light squared (c²) in m² s⁻².
155#[cfg(feature = "physics")]
156pub const C_SQUARED: Real = C * C;
157
158/// GM☉ / c³ in seconds (from `GM_SUN` and `C` — used in Shapiro delay)
159#[cfg(feature = "physics")]
160pub const GM_SUN_OVER_C3: Real = GM_SUN / (C * C_SQUARED);
161
162/// 2GM☉ / c³ — the standard prefactor in the one-way Shapiro delay formula
163#[cfg(feature = "physics")]
164pub const TWO_GM_SUN_OVER_C3: Real = 2.0 * GM_SUN_OVER_C3;
165
166/// Planck length ℓ_Pl in meters (standard value).
167///
168/// This is raised to the fourth power to form the dimensionless curvature
169/// parameter `x = ℓ_Pl⁴ × 𝒦` inside the master Lagrangian. The term only
170/// affects the proper-time rate at extreme (Planckian) curvatures.
171/// See the [relativistic timing model](https://github.com/ragardner/deep-time/blob/main/docs/relativity.md).
172#[cfg(feature = "physics")]
173pub const PLANCK_LENGTH: Real = 1.616255e-35;
174
175/// Planck length to the fourth power (ℓ_Pl⁴) in m⁴.
176///
177/// This is the coefficient actually used at runtime:
178///
179/// ```text
180/// let x = PLANCK_LENGTH_4 * kretschmann;
181/// ```
182///
183/// The fourth power produces a dimensionless `x` because the Kretschmann
184/// scalar has units of L⁻⁴. Information on the underlying model can be found
185/// [here](https://github.com/ragardner/deep-time/blob/main/docs/relativity.md).
186#[cfg(feature = "physics")]
187pub const PLANCK_LENGTH_4: Real = PLANCK_LENGTH * PLANCK_LENGTH * PLANCK_LENGTH * PLANCK_LENGTH;