mod arithmetic;
mod constructors;
mod conveniences;
mod conversions;
mod decimal_year;
mod from_ccsds;
mod from_str;
mod gregorian;
mod julian_date;
mod ops;
mod tdb;
mod to_bin_ccsds;
mod to_str;
pub mod lunar;
pub mod numbers_traits;
pub mod trajectory;
#[cfg(feature = "alloc")]
mod formatting;
#[cfg(feature = "alloc")]
mod to_str_ccsds;
#[cfg(feature = "mars")]
pub mod mars;
#[cfg(feature = "hifitime")]
mod hifitime;
#[cfg(feature = "chrono")]
mod chrono;
#[cfg(feature = "jiff")]
mod jiff;
use crate::ATTOS_PER_SEC;
use core::fmt;
#[derive(Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "js", derive(tsify::Tsify))]
pub struct Dt {
pub sec: i64,
pub attos: u64,
}
impl Dt {
#[inline]
pub const fn carry_attos_mut(&mut self) -> &mut Self {
if self.attos >= ATTOS_PER_SEC {
self.sec = self.sec.saturating_add((self.attos / ATTOS_PER_SEC) as i64);
self.attos %= ATTOS_PER_SEC;
}
self
}
#[inline]
pub const fn carry_attos(&self) -> Self {
if self.attos < ATTOS_PER_SEC {
return *self;
}
Self {
sec: self.sec.saturating_add((self.attos / ATTOS_PER_SEC) as i64),
attos: self.attos % ATTOS_PER_SEC,
}
}
}
impl Default for Dt {
fn default() -> Self {
Self::ZERO
}
}
impl fmt::Display for Dt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let sec = self.sec;
let attos = self.attos;
let precision = f.precision().unwrap_or(9);
if f.sign_plus() && sec >= 0 {
write!(f, "+")?;
}
write!(f, "{}", sec)?;
if precision > 0 {
let prec = precision.min(18);
let scale = 10u64.pow(18 - prec as u32);
let value = attos / scale;
write!(f, ".{:0>width$}", value, width = prec)?;
}
Ok(())
}
}
impl fmt::Debug for Dt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Dt")
.field("sec", &self.sec)
.field("attos", &self.attos)
.finish()
}
}