deep-time 0.1.0-beta.2

High-precision, no-std, no-alloc date-time library, leap-seconds, time scales, relativistic time, and a powerful date & duration parser
Documentation
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
//! Sidereal rotation and time calculations for celestial bodies.
//!
//! [`Sidereal`] struct with ready-to-use `EARTH`, `MARS`, `MOON` constants.
//! Computes rotation angle, LMST/LAST, GMST/GAST.
//!
//! With the `"sidereal-earth"` feature enabled a rust implementation of the
//! ERFA Earth Equation of the Origins / Equinoxes are both available as well.

#[cfg(feature = "sidereal-earth")]
pub mod earth_eo_ee;

use crate::Real;
use core::f64::consts::TAU;

#[cfg(feature = "sidereal-earth")]
use earth_eo_ee::*;

/// Represents the rotational state of a celestial body and provides
/// methods to compute the orientation of its prime meridian at any
/// given time.
///
/// The rotation angle of the prime meridian is the basis for
/// calculating local sidereal time. Local sidereal time is required
/// to compute the hour angle of a celestial object (HA = LST − RA),
/// to determine when an object will cross the local meridian,
/// to convert between horizon coordinates (altitude/azimuth) and
/// equatorial coordinates, and to calculate accurate pointing
/// directions for telescopes and spacecraft antennas.
///
/// The struct implements the modern CIO-based rotation model and
/// works for any rotating body (Earth, Mars, the Moon, etc.) by
/// supplying the appropriate rotation rate and reference values.
///
/// ## Fields
///
/// * `rate_rad_per_sec` — Mean sidereal rotation rate in radians per SI second.
/// * `ref_epoch` — Reference epoch (MJD) at which `ref_angle_rad` is defined.
/// * `ref_angle_rad` — Rotation angle of the prime meridian at `ref_epoch`.
/// * `longitude_rad` — Observer longitude on the body (radians, east positive).
///   `0.0` corresponds to the body's prime meridian.
/// * `correction_rad` — General-purpose additive correction in radians.
///
/// ## Examples
///
/// Basic usage with Earth constants:
///
/// ```rust
/// use deep_time::Sidereal;
///
/// let mut earth = Sidereal::EARTH;
/// earth.longitude_rad = 0.0; // Greenwich
///
/// let mjd = 60000.0;
/// let era = earth.rotation_angle(mjd);
///
/// // Local Mean Sidereal Time using the mean Equation of the Origins
/// let eo_mean = earth.earth_eo_mean(mjd + 32.184 / 86400.0);
/// let lmst = earth.local_sidereal_time_mean(mjd, eo_mean);
/// ```
///
/// Realistic usage with DUT1 correction (UT1 time scale):
///
/// ```rust
/// use deep_time::{Dt, Sidereal};
/// use deep_time::eop::{EopData, EopFormat, Separator};
///
/// let eop = EopData::from_text_file(
///     "finals.all.iau2000.txt",
///     EopFormat::Finals2000A,
///     Separator::Whitespace,
/// ).unwrap();
///
/// let mjd_utc = 56879.0;
/// let dut1 = Dt::mjd_to_eop_offset_f(mjd_utc, &eop).unwrap();
/// let mjd_ut1 = mjd_utc + dut1 / 86400.0;
///
/// let earth = Sidereal::EARTH;
///
/// let era = earth.rotation_angle(mjd_ut1);
///
/// // Greenwich Mean Sidereal Time
/// let eo_mean = earth.earth_eo_mean(mjd_ut1 + 32.184 / 86400.0);
/// let gmst = earth.sidereal_angle_mean(mjd_ut1, eo_mean);
///
/// // Local Mean Sidereal Time
/// let lmst = earth.local_sidereal_time_mean(mjd_ut1, eo_mean);
/// ```
#[derive(Debug, Clone, Copy)]
pub struct Sidereal {
    /// Mean sidereal rotation rate in **radians per SI second**.
    pub rate_rad_per_sec: Real,
    /// Reference epoch.
    pub ref_epoch: Real,
    /// Rotation angle of the prime meridian (radians) at `ref_epoch`.
    pub ref_angle_rad: Real,
    /// Longitude of the observer on the body (radians, east positive).
    /// `0.0` = body's prime meridian.
    pub longitude_rad: Real,
    /// General scalar correction in radians.
    pub correction_rad: Real,
}

impl Sidereal {
    /// Pre-configured `Sidereal` for Earth using IAU 2000/2006 conventions.
    ///
    /// This uses:
    /// - The conventional mean sidereal rotation rate of Earth.
    /// - J2000.0 as the reference epoch (`ref_epoch = 51544.5`).
    /// - The Earth Rotation Angle (ERA) at J2000.0 as `ref_angle_rad`.
    ///
    /// You can still customize fields after construction (e.g. `longitude_rad`
    /// or `correction_rad`).
    pub const EARTH: Self = Self {
        rate_rad_per_sec: (1.00273781191135448 * core::f64::consts::TAU) / 86400.0,
        ref_epoch: 51544.5,
        ref_angle_rad: 0.7790572732640 * core::f64::consts::TAU,
        longitude_rad: 0.0,
        correction_rad: 0.0,
    };

    /// Pre-configured `Sidereal` for Mars.
    ///
    /// Uses a simplified mean sidereal rotation rate and J2000.0 as the
    /// reference epoch. `ref_angle_rad` is set to zero (no specific
    /// reference angle is defined).
    ///
    /// You can customize fields (especially `longitude_rad`) after construction.
    pub const MARS: Self = Self {
        rate_rad_per_sec: core::f64::consts::TAU / 88642.663,
        ref_epoch: 51544.5,
        ref_angle_rad: 0.0,
        longitude_rad: 0.0,
        correction_rad: 0.0,
    };

    /// Pre-configured `Sidereal` for the Moon.
    ///
    /// Uses a simplified mean sidereal rotation rate and J2000.0 as the
    /// reference epoch. `ref_angle_rad` is set to zero (no specific
    /// reference angle is defined).
    ///
    /// You can customize fields (especially `longitude_rad`) after construction.
    pub const MOON: Self = Self {
        rate_rad_per_sec: core::f64::consts::TAU / 2_360_591.424,
        ref_epoch: 51544.5,
        ref_angle_rad: 0.0,
        longitude_rad: 0.0,
        correction_rad: 0.0,
    };

    // Normalize to [0, 2π)
    #[inline]
    const fn normalize_angle(angle: Real) -> Real {
        ((angle % TAU) + TAU) % TAU
    }

    /// Returns the instantaneous rotation angle of the body's prime meridian
    /// (in radians) at the given instant, normalized to `[0, 2π)`.
    ///
    /// For Earth this is the pure Earth Rotation Angle (ERA) in the
    /// Celestial Intermediate Origin (CIO) frame. It does **not** include
    /// observer longitude or the Equation of the Origins.
    ///
    /// Matches Astropy's `Time.earth_rotation_angle(longitude=None)`
    /// (or with `longitude=0`).
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let era = Sidereal::EARTH.rotation_angle(57753.5);
    /// ```
    pub const fn rotation_angle(&self, mjd: Real) -> Real {
        // elapsed time in seconds between ref_epoch (MJD) and the given mjd
        let elapsed_days = mjd - self.ref_epoch;
        let elapsed_sec = elapsed_days * 86400.0;

        let angle = self.ref_angle_rad + self.rate_rad_per_sec * elapsed_sec + self.correction_rad;

        Self::normalize_angle(angle)
    }

    /// Returns the rotation angle of the prime meridian at the observer's
    /// longitude, normalized to `[0, 2π)`.
    ///
    /// This is equivalent to `rotation_angle(mjd) + self.longitude_rad`.
    /// It gives the angle between the Celestial Intermediate Origin (CIO)
    /// and the observer’s local meridian.
    ///
    /// This value is commonly used when computing the local hour angle
    /// of a celestial object:
    ///
    /// ```text
    /// HA = local_rotation_angle(mjd) - RA
    /// ```
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let mut earth = Sidereal::EARTH;
    /// earth.longitude_rad = 0.0; // Greenwich
    ///
    /// let mjd = 60000.0;
    /// let local_era = earth.local_rotation_angle(mjd);
    /// ```
    #[inline]
    pub const fn local_rotation_angle(&self, mjd: Real) -> Real {
        Self::normalize_angle(self.rotation_angle(mjd) + self.longitude_rad)
    }

    /// Returns the sidereal angle of the body's prime meridian in radians,
    /// normalized to `[0, 2π)`.
    ///
    /// This computes Greenwich Mean Sidereal Time (GMST) when an appropriate
    /// Equation of the Origins value is supplied.
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The Equation of the Origins value to subtract from the
    ///   Earth Rotation Angle (ERA).  
    ///   - Pass `0.0` to get the pure CIO-based rotation angle (ERA).
    ///   - Pass the **mean** Equation of the Origins (e.g. from
    ///     [`earth_eo_mean`](Self::earth_eo_mean)) to obtain GMST.
    ///
    /// ## Details
    ///
    /// - When `eo_rad = 0.0`, the result is the modern Earth Rotation Angle (ERA)
    ///   relative to the Celestial Intermediate Origin (CIO).
    ///
    /// - When `eo_rad` is the mean Equation of the Origins (i.e. the value that
    ///   satisfies `GMST = ERA − eo_rad`), the result is Greenwich Mean Sidereal
    ///   Time (GMST) referred to the mean equinox. This is the traditional
    ///   equinox-based mean sidereal time.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let earth = Sidereal::EARTH;
    /// let mjd = 60000.0;
    ///
    /// // Pure CIO-based rotation angle (Earth Rotation Angle)
    /// let era = earth.sidereal_angle_mean(mjd, 0.0);
    ///
    /// // Traditional mean sidereal time using the mean Equation of the Origins
    /// // convert to the mjd to tt if necessary
    /// let eo_mean = earth.earth_eo_mean(mjd + 32.184 / 86400.0);
    /// let gmst = earth.sidereal_angle_mean(mjd, eo_mean);
    /// ```
    #[inline]
    pub const fn sidereal_angle_mean(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.rotation_angle(mjd) - eo_rad;
        Self::normalize_angle(angle)
    }

    /// Returns the local sidereal angle at the observer's longitude in radians,
    /// normalized to `[0, 2π)`.
    ///
    /// This computes **Local Mean Sidereal Time (LMST)** when an appropriate
    /// Equation of the Origins value is supplied.
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The Equation of the Origins value to subtract from the
    ///   Earth Rotation Angle (ERA).  
    ///   - Pass `0.0` to get the pure local Earth Rotation Angle (CIO-based).
    ///   - Pass the **mean** Equation of the Origins (e.g. from
    ///     [`earth_eo_mean`](Self::earth_eo_mean)) to obtain Local Mean
    ///     Sidereal Time (LMST).
    ///
    /// ## Details
    ///
    /// - When `eo_rad = 0.0`, the result is the local Earth Rotation Angle
    ///   relative to the Celestial Intermediate Origin (CIO) at the observer’s
    ///   longitude.
    ///
    /// - When `eo_rad` is the mean Equation of the Origins, the result is
    ///   **Local Mean Sidereal Time (LMST)** referred to the mean equinox.
    ///
    /// This value is commonly used when calculating the local hour angle of a
    /// celestial object:
    ///
    /// ```text
    /// HA = local_sidereal_angle_mean(mjd, eo) − RA
    /// ```
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let mut earth = Sidereal::EARTH;
    /// earth.longitude_rad = 0.0; // Greenwich
    ///
    /// let mjd = 60000.0;
    ///
    /// // Pure local Earth Rotation Angle (CIO-based)
    /// let local_era = earth.local_sidereal_angle_mean(mjd, 0.0);
    ///
    /// // Local Mean Sidereal Time using the mean Equation of the Origins
    /// let eo_mean = earth.earth_eo_mean(mjd + 32.184 / 86400.0);
    /// let lmst = earth.local_sidereal_angle_mean(mjd, eo_mean);
    /// ```
    #[inline]
    pub const fn local_sidereal_angle_mean(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.rotation_angle(mjd) + self.longitude_rad - eo_rad;
        Self::normalize_angle(angle)
    }

    /// Returns sidereal time at the body's prime meridian as seconds since
    /// sidereal midnight, wrapped to the range `[0, 86400)`.
    ///
    /// This is the time equivalent of [`sidereal_angle_mean`].
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The Equation of the Origins value to use.  
    ///   - Pass `0.0` to get the time equivalent of the pure Earth Rotation Angle (ERA).  
    ///   - Pass the **mean** Equation of the Origins (e.g. from
    ///     [`earth_eo_mean`](Self::earth_eo_mean)) to obtain Greenwich Mean
    ///     Sidereal Time (GMST).
    ///
    /// ## Details
    ///
    /// - When `eo_rad = 0.0`, the result is the time equivalent of the modern
    ///   Earth Rotation Angle (ERA).
    ///
    /// - When `eo_rad` is the mean Equation of the Origins, the result is
    ///   **Greenwich Mean Sidereal Time (GMST)** referred to the mean equinox.
    ///
    /// As of Astropy 7.x, this is consistent with
    /// `Time.sidereal_time("mean").to_value("sec")` (when no longitude is
    /// specified) when using matching UT1 time and the mean Equation of the Origins.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let earth = Sidereal::EARTH;
    /// let mjd = 60000.0;
    ///
    /// // Time equivalent of pure Earth Rotation Angle
    /// let era_seconds = earth.sidereal_time_mean(mjd, 0.0);
    ///
    /// // Greenwich Mean Sidereal Time in seconds
    /// let eo_mean = earth.earth_eo_mean(mjd + 32.184 / 86400.0);
    /// let gmst_seconds = earth.sidereal_time_mean(mjd, eo_mean);
    /// ```
    pub const fn sidereal_time_mean(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.sidereal_angle_mean(mjd, eo_rad);
        let fraction = ((angle / TAU) % 1.0 + 1.0) % 1.0;
        fraction * 86400.0
    }

    /// Returns local sidereal time at the observer's longitude as seconds since
    /// sidereal midnight, wrapped to the range `[0, 86400)`.
    ///
    /// This is the time equivalent of [`local_sidereal_angle_mean`].
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The Equation of the Origins value to use.  
    ///   - Pass `0.0` to get the time equivalent of the local Earth Rotation Angle (CIO-based).  
    ///   - Pass the **mean** Equation of the Origins (e.g. from
    ///     [`earth_eo_mean`](Self::earth_eo_mean)) to obtain **Local Mean Sidereal Time (LMST)**.
    ///
    /// ## Details
    ///
    /// - When `eo_rad = 0.0`, the result is the time equivalent of the local
    ///   Earth Rotation Angle relative to the Celestial Intermediate Origin (CIO)
    ///   at the observer’s longitude.
    ///
    /// - When `eo_rad` is the mean Equation of the Origins, the result is
    ///   **Local Mean Sidereal Time (LMST)** referred to the mean equinox.
    ///
    /// As of Astropy 7.x, this is consistent with
    /// `Time.sidereal_time("mean", longitude=...).to_value("sec")` when using
    /// matching UT1 time and the mean Equation of the Origins.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let mut earth = Sidereal::EARTH;
    /// earth.longitude_rad = 0.0; // Greenwich
    ///
    /// let mjd = 60000.0;
    ///
    /// // Time equivalent of local Earth Rotation Angle
    /// let local_era_seconds = earth.local_sidereal_time_mean(mjd, 0.0);
    ///
    /// // Local Mean Sidereal Time in seconds
    /// let eo_mean = earth.earth_eo_mean(mjd + 32.184 / 86400.0);
    /// let lmst_seconds = earth.local_sidereal_time_mean(mjd, eo_mean);
    /// ```
    pub const fn local_sidereal_time_mean(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.local_sidereal_angle_mean(mjd, eo_rad);
        let fraction = ((angle / TAU) % 1.0 + 1.0) % 1.0;
        fraction * 86400.0
    }

    /// Returns the apparent sidereal angle of the body's prime meridian
    /// in radians, normalized to `[0, 2π)`.
    ///
    /// This computes **Greenwich Apparent Sidereal Time (GAST)** when the
    /// apparent Equation of the Origins is supplied.
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The **apparent** Equation of the Origins
    ///   (e.g. from [`earth_eo_apparent`](Self::earth_eo_apparent)).
    ///   When supplied, the result is Greenwich Apparent Sidereal Time (GAST)
    ///   referred to the true equinox.
    ///
    /// ## Details
    ///
    /// This function implements the direct relationship:
    ///
    /// ```text
    /// GAST = ERA − EO_apparent
    /// ```
    ///
    /// As of Astropy 7.x, this is consistent with
    /// `Time.sidereal_time("apparent").rad` (when no longitude is specified)
    /// when using matching UT1 time and the apparent Equation of the Origins.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let earth = Sidereal::EARTH;
    /// let mjd = 60000.0;
    ///
    /// // Greenwich Apparent Sidereal Time
    /// let eo_app = earth.earth_eo_apparent(mjd + 32.184 / 86400.0);
    /// let gast = earth.sidereal_angle_apparent(mjd, eo_app);
    /// ```
    pub const fn sidereal_angle_apparent(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.rotation_angle(mjd) - eo_rad;
        Self::normalize_angle(angle)
    }

    /// Returns the local apparent sidereal angle at the observer's longitude
    /// in radians, normalized to `[0, 2π)`.
    ///
    /// This computes **Local Apparent Sidereal Time (LAST)** when the
    /// apparent Equation of the Origins is supplied.
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The **apparent** Equation of the Origins
    ///   (e.g. from [`earth_eo_apparent`](Self::earth_eo_apparent)).
    ///   When supplied, the result is Local Apparent Sidereal Time (LAST)
    ///   at the observer’s longitude, referred to the true equinox.
    ///
    /// ## Details
    ///
    /// This function implements the direct relationship:
    ///
    /// ```text
    /// LAST = ERA + longitude − EO_apparent
    /// ```
    ///
    /// As of Astropy 7.x, this is consistent with
    /// `Time.sidereal_time("apparent", longitude=...).rad` when using
    /// matching UT1 time and the apparent Equation of the Origins.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let mut earth = Sidereal::EARTH;
    /// earth.longitude_rad = 0.0; // Greenwich
    ///
    /// let mjd = 60000.0;
    ///
    /// // Local Apparent Sidereal Time
    /// let eo_app = earth.earth_eo_apparent(mjd + 32.184 / 86400.0);
    /// let last = earth.local_sidereal_angle_apparent(mjd, eo_app);
    /// ```
    pub const fn local_sidereal_angle_apparent(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.rotation_angle(mjd) + self.longitude_rad - eo_rad;
        Self::normalize_angle(angle)
    }

    /// Returns apparent sidereal time at the body's prime meridian as seconds
    /// since sidereal midnight, wrapped to the range `[0, 86400)`.
    ///
    /// This is the time equivalent of [`sidereal_angle_apparent`].
    ///
    /// When the **apparent** Equation of the Origins is supplied, this function
    /// returns **Greenwich Apparent Sidereal Time (GAST)**.
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The **apparent** Equation of the Origins
    ///   (e.g. from [`earth_eo_apparent`](Self::earth_eo_apparent)).
    ///   When supplied, the result is Greenwich Apparent Sidereal Time (GAST)
    ///   in seconds since sidereal midnight.
    ///
    /// ## Details
    ///
    /// This function computes:
    ///
    /// ```text
    /// GAST (seconds) = (ERA − EO_apparent) in fractional days × 86400
    /// ```
    ///
    /// As of Astropy 7.x, this is consistent with
    /// `Time.sidereal_time("apparent").to_value("sec")` (Greenwich) when using
    /// matching UT1 time and the apparent Equation of the Origins.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let earth = Sidereal::EARTH;
    /// let mjd = 60000.0;
    ///
    /// // Greenwich Apparent Sidereal Time in seconds
    /// let eo_app = earth.earth_eo_apparent(mjd + 32.184 / 86400.0);
    /// let gast_seconds = earth.sidereal_time_apparent(mjd, eo_app);
    /// ```
    pub const fn sidereal_time_apparent(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.sidereal_angle_apparent(mjd, eo_rad);
        let fraction = ((angle / TAU) % 1.0 + 1.0) % 1.0;
        fraction * 86400.0
    }

    /// Returns local apparent sidereal time at the observer's longitude as
    /// seconds since sidereal midnight, wrapped to the range `[0, 86400)`.
    ///
    /// This is the time equivalent of [`local_sidereal_angle_apparent`].
    ///
    /// When the **apparent** Equation of the Origins is supplied, this function
    /// returns **Local Apparent Sidereal Time (LAST)**.
    ///
    /// ## Parameters
    ///
    /// - `eo_rad`: The **apparent** Equation of the Origins
    ///   (e.g. from [`earth_eo_apparent`](Self::earth_eo_apparent)).
    ///   When supplied, the result is Local Apparent Sidereal Time (LAST)
    ///   at the observer’s longitude, in seconds since sidereal midnight.
    ///
    /// ## Details
    ///
    /// This function computes:
    ///
    /// ```text
    /// LAST (seconds) = (ERA + longitude − EO_apparent) in fractional days × 86400
    /// ```
    ///
    /// As of Astropy 7.x, this is consistent with
    /// `Time.sidereal_time("apparent", longitude=...).to_value("sec")` when using
    /// matching UT1 time and the apparent Equation of the Origins.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let mut earth = Sidereal::EARTH;
    /// earth.longitude_rad = 0.0; // Greenwich
    ///
    /// let mjd = 60000.0;
    ///
    /// // Local Apparent Sidereal Time in seconds
    /// let eo_app = earth.earth_eo_apparent(mjd + 32.184 / 86400.0);
    /// let last_seconds = earth.local_sidereal_time_apparent(mjd, eo_app);
    /// ```
    pub const fn local_sidereal_time_apparent(&self, mjd: Real, eo_rad: Real) -> Real {
        let angle = self.local_sidereal_angle_apparent(mjd, eo_rad);
        let fraction = ((angle / TAU) % 1.0 + 1.0) % 1.0;
        fraction * 86400.0
    }

    /// Returns the apparent Equation of the Origins (radians) at the given MJD.
    ///
    /// This returns the value computed by ERFA’s `eo06a`. It is the modern
    /// CIO-based quantity used to derive **Greenwich Apparent Sidereal Time (GAST)**
    /// from the Earth Rotation Angle (ERA).
    ///
    /// When you subtract this value from the ERA, you get GAST:
    ///
    /// ```text
    /// GAST = ERA − earth_eo_apparent(...)
    /// ```
    ///
    /// This method is equivalent to calling `erfa.eo06a(tt.jd1, tt.jd2)` in Astropy.
    ///
    /// You should pass the value returned by this function to the apparent
    /// sidereal time functions (`sidereal_angle_apparent`, `local_sidereal_angle_apparent`,
    /// `sidereal_time_apparent`, and `local_sidereal_time_apparent`).
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let earth = Sidereal::EARTH;
    /// let mjd_tt = 60000.0 + 32.184 / 86400.0;
    ///
    /// let eo_app = earth.earth_eo_apparent(mjd_tt);
    /// let gast = earth.sidereal_angle_apparent(mjd_tt, eo_app);
    /// ```
    #[cfg(feature = "sidereal-earth")]
    #[inline]
    pub const fn earth_eo_apparent(&self, tt_mjd: Real) -> Real {
        // Convert MJD → two-part Julian Date
        let date1 = 2400000.5 + tt_mjd;
        earth_eo(date1, 0.0)
    }

    /// Returns the mean Equation of the Origins (radians) at the given MJD.
    ///
    /// This returns the value that should be subtracted from the Earth Rotation
    /// Angle (ERA) to obtain **Greenwich Mean Sidereal Time (GMST)**:
    ///
    /// ```text
    /// GMST = ERA − earth_eo_mean(...)
    /// ```
    ///
    /// Internally, this is computed as:
    ///
    /// ```text
    /// earth_eo_mean = earth_eo_apparent() + earth_ee()
    /// ```
    ///
    /// This is equivalent to computing `era - gmst` in Astropy:
    ///
    /// ```python
    /// era = ut1.earth_rotation_angle(...).rad
    /// gmst = ut1.sidereal_time("mean", ...).rad
    /// eo_mean = era - gmst
    /// ```
    ///
    /// You should pass the value returned by this function to the mean
    /// sidereal time functions (`sidereal_angle_mean`, `local_sidereal_angle_mean`,
    /// `sidereal_time_mean`, and `local_sidereal_time_mean`).
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let earth = Sidereal::EARTH;
    /// let mjd_tt = 60000.0 + 32.184 / 86400.0;
    ///
    /// let eo_mean = earth.earth_eo_mean(mjd_tt);
    /// let gmst = earth.sidereal_angle_mean(mjd_tt, eo_mean);
    /// ```
    #[cfg(feature = "sidereal-earth")]
    #[inline]
    pub const fn earth_eo_mean(&self, tt_mjd: Real) -> Real {
        // Convert MJD → two-part Julian Date
        let date1 = 2400000.5 + tt_mjd;
        earth_eo(date1, 0.0) + earth_ee(date1, 0.0)
    }

    /// Returns the Equation of the Equinoxes (radians) at the given MJD.
    ///
    /// This returns the value computed by ERFA’s `ee06a`. The Equation of the
    /// Equinoxes represents the nutation contribution to sidereal time and is
    /// defined as:
    ///
    /// ```text
    /// EE = GAST − GMST
    /// ```
    ///
    /// It is equivalent to computing `gast - gmst` in Astropy:
    ///
    /// ```python
    /// gast = ut1.sidereal_time("apparent", ...).rad
    /// gmst = ut1.sidereal_time("mean", ...).rad
    /// ee = gast - gmst
    /// ```
    ///
    /// This value is used internally when converting between mean and apparent
    /// sidereal time (for example, when the mean functions are given the apparent
    /// EO + EE).
    ///
    /// ## Example
    ///
    /// ```rust
    /// use deep_time::Sidereal;
    ///
    /// let earth = Sidereal::EARTH;
    /// let mjd_tt = 60000.0 + 32.184 / 86400.0;
    ///
    /// let ee = earth.earth_ee(mjd_tt);
    /// ```
    #[cfg(feature = "sidereal-earth")]
    #[inline]
    pub const fn earth_ee(&self, tt_mjd: Real) -> Real {
        // Convert MJD → two-part Julian Date
        let date1 = 2400000.5 + tt_mjd;
        earth_ee(date1, 0.0)
    }
}