1use crate::{ATTOS_PER_SEC_I128, ATTOS_PER_WEEK, Dt, Real, SEC_PER_DAYI64, Scale};
2
3impl Dt {
4 pub const fn to_gps_wk_and_tow(&self, current: Scale) -> (i64, Dt) {
7 let total_attos = self.to_gps(current).to_attos();
8
9 let wk = total_attos.div_euclid(ATTOS_PER_WEEK) as i64;
10 let tow_attos = total_attos.rem_euclid(ATTOS_PER_WEEK);
11
12 (wk, Dt::from_attos(tow_attos, Scale::TAI))
13 }
14
15 pub const fn to_gps_day_of_wk(&self, current: Scale) -> u8 {
20 let (_, tow) = self.to_gps_wk_and_tow(current);
21 let secs = tow.to_attos() / ATTOS_PER_SEC_I128;
22
23 (secs / SEC_PER_DAYI64 as i128) as u8
24 }
25
26 #[inline]
31 pub const fn to_gps_tow_f(&self, current: Scale) -> Real {
32 let (_, tow) = self.to_gps_wk_and_tow(current);
33 tow.to_sec_f()
34 }
35
36 #[inline]
38 pub const fn to_gps_wk(&self, current: Scale) -> i64 {
39 self.to_gps_wk_and_tow(current).0
40 }
41
42 #[inline]
43 pub const fn to_galexsec(&self, current: Scale) -> Dt {
44 self.to(current, Scale::UTC)
45 .to_diff_raw(Dt::GPS_EPOCH.to(Scale::TAI, Scale::UTC))
46 }
47
48 #[inline]
49 pub const fn to_gps(&self, current: Scale) -> Dt {
50 self.to(current, Scale::GPS)
51 .to_diff_raw(Dt::GPS_EPOCH.to(Scale::TAI, Scale::GPS))
52 }
53
54 #[inline]
55 pub const fn to_cxcsec(&self, current: Scale) -> Dt {
56 self.to(current, Scale::TT)
57 .to_diff_raw(Dt::CXC_EPOCH.to(Scale::TAI, Scale::TT))
58 }
59}