Skip to main content

celestial_time/sidereal/
conversions.rs

1use super::{GAST, GMST, LAST, LMST};
2
3impl From<LMST> for GMST {
4    fn from(lmst: LMST) -> GMST {
5        lmst.to_gmst()
6    }
7}
8
9impl From<LAST> for GAST {
10    fn from(last: LAST) -> GAST {
11        last.to_gast()
12    }
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18    use celestial_core::Location;
19
20    fn mauna_kea() -> Location {
21        Location::from_degrees(19.8283, -155.4783, 4145.0).unwrap()
22    }
23
24    #[test]
25    fn test_lmst_to_gmst_conversion() {
26        let location = mauna_kea();
27        let lmst = LMST::from_hours(12.0, &location);
28        let gmst: GMST = lmst.into();
29
30        let expected_hours = 12.0 - (-155.4783 / 15.0);
31        assert!((gmst.hours() - expected_hours).abs() < 1e-12);
32    }
33
34    #[test]
35    fn test_last_to_gast_conversion() {
36        let location = mauna_kea();
37        let last = LAST::from_hours(12.0, &location);
38        let gast: GAST = last.into();
39
40        let expected_hours = 12.0 - (-155.4783 / 15.0);
41        assert!((gast.hours() - expected_hours).abs() < 1e-12);
42    }
43
44    #[test]
45    fn test_gmst_to_lmst_conversion() {
46        let location = mauna_kea();
47        let gmst = GMST::from_hours(12.0);
48        let lmst = gmst.to_lmst(&location);
49
50        let expected_hours = 12.0 + (-155.4783 / 15.0);
51        let expected_normalized = if expected_hours < 0.0 {
52            expected_hours + 24.0
53        } else {
54            expected_hours
55        };
56        assert!((lmst.hours() - expected_normalized).abs() < 1e-12);
57    }
58
59    #[test]
60    fn test_gast_to_last_conversion() {
61        let location = mauna_kea();
62        let gast = GAST::from_hours(12.0);
63        let last = gast.to_last(&location);
64
65        let expected_hours = 12.0 + (-155.4783 / 15.0);
66        let expected_normalized = if expected_hours < 0.0 {
67            expected_hours + 24.0
68        } else {
69            expected_hours
70        };
71        assert!((last.hours() - expected_normalized).abs() < 1e-12);
72    }
73}