tempoch_core/
julian_date_ext.rs1use qtty::*;
7use std::ops::Add;
8
9use super::instant::Time;
10use super::scales::{JD, MJD};
11
12impl Time<JD> {
13 pub const J2000: Self = Self::new(2_451_545.0);
15
16 pub const JULIAN_YEAR: Days = Days::new(365.25);
18
19 pub const JULIAN_CENTURY: Days = Days::new(36_525.0);
21
22 pub const JULIAN_MILLENNIUM: Days = Days::new(365_250.0);
24
25 #[inline]
27 pub fn julian_millennias(&self) -> Millennia {
28 Millennia::new(
29 ((*self - Self::J2000) / Self::JULIAN_MILLENNIUM)
30 .simplify()
31 .value(),
32 )
33 }
34
35 #[inline]
37 pub fn julian_centuries(&self) -> Centuries {
38 Centuries::new(
39 ((*self - Self::J2000) / Self::JULIAN_CENTURY)
40 .simplify()
41 .value(),
42 )
43 }
44
45 #[inline]
47 pub fn julian_years(&self) -> JulianYears {
48 JulianYears::new(
49 ((*self - Self::J2000) / Self::JULIAN_YEAR)
50 .simplify()
51 .value(),
52 )
53 }
54
55 pub fn tt_to_tdb(jd_tt: Self) -> Self {
70 jd_tt + super::scales::tdb_minus_tt_days(jd_tt.quantity())
71 }
72
73 #[inline]
77 pub fn to_mjd(&self) -> Time<MJD> {
78 self.to::<MJD>()
79 }
80}
81
82impl Add<Years> for Time<JD> {
85 type Output = Self;
86 fn add(self, years: Years) -> Self {
87 self + Days::new(years.value() * Self::JULIAN_YEAR.value())
89 }
90}
91
92impl From<JulianYears> for Time<JD> {
93 fn from(years: JulianYears) -> Self {
94 Self::J2000 + years.to::<Day>()
95 }
96}
97
98impl From<Time<JD>> for JulianYears {
99 fn from(jd: Time<JD>) -> Self {
100 jd.julian_years()
101 }
102}
103
104impl From<Centuries> for Time<JD> {
105 fn from(centuries: Centuries) -> Self {
106 Self::J2000 + Days::new(centuries.value() * Self::JULIAN_CENTURY.value())
108 }
109}
110
111impl From<Time<JD>> for Centuries {
112 fn from(jd: Time<JD>) -> Self {
113 jd.julian_centuries()
114 }
115}
116
117impl From<Millennia> for Time<JD> {
118 fn from(millennia: Millennia) -> Self {
119 Self::J2000 + Days::new(millennia.value() * Self::JULIAN_MILLENNIUM.value())
121 }
122}
123
124impl From<Time<JD>> for Millennia {
125 fn from(jd: Time<JD>) -> Self {
126 jd.julian_millennias()
127 }
128}