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
//! Astronomical timescale selector.
use core::fmt;
use supernovas_ffi::novas_timescale;
/// An astronomical timescale.
///
/// Identifies which timescale a Julian date or time interval is expressed in.
/// Pass a `Timescale` to [`crate::Time::from_jd`], [`crate::Time::jd`],
/// [`crate::Interval::from_seconds`], and related methods to avoid leaking
/// raw FFI constants into user code.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Timescale {
/// Barycentric Coordinate Time (TCB).
Tcb,
/// Barycentric Dynamical Time (TDB).
Tdb,
/// Geocentric Coordinate Time (TCG).
Tcg,
/// Terrestrial Time (TT).
Tt,
/// International Atomic Time (TAI).
Tai,
/// GPS Time.
Gps,
/// Universal Coordinated Time (UTC).
Utc,
/// UT1 earth rotation time, based on IERS Bulletin A.
Ut1,
}
impl Timescale {
pub(crate) fn to_sys(self) -> novas_timescale {
match self {
Timescale::Tcb => novas_timescale::NOVAS_TCB,
Timescale::Tdb => novas_timescale::NOVAS_TDB,
Timescale::Tcg => novas_timescale::NOVAS_TCG,
Timescale::Tt => novas_timescale::NOVAS_TT,
Timescale::Tai => novas_timescale::NOVAS_TAI,
Timescale::Gps => novas_timescale::NOVAS_GPS,
Timescale::Utc => novas_timescale::NOVAS_UTC,
Timescale::Ut1 => novas_timescale::NOVAS_UT1,
}
}
}
impl fmt::Display for Timescale {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Timescale::Tcb => "TCB",
Timescale::Tdb => "TDB",
Timescale::Tcg => "TCG",
Timescale::Tt => "TT",
Timescale::Tai => "TAI",
Timescale::Gps => "GPS",
Timescale::Utc => "UTC",
Timescale::Ut1 => "UT1",
})
}
}