use core::fmt;
use crate::{Epoch, TimeScale};
impl fmt::Display for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (y, mm, dd, hh, min, s, nanos) =
Self::compute_gregorian(self.duration, self.time_scale);
if nanos == 0 {
write!(
f,
"{:04}-{:02}-{:02}T{:02}:{:02}:{:02} {}",
y, mm, dd, hh, min, s, self.time_scale
)
} else {
write!(
f,
"{:04}-{:02}-{:02}T{:02}:{:02}:{:02}.{:09} {}",
y, mm, dd, hh, min, s, nanos, self.time_scale
)
}
}
}
impl fmt::Debug for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ts = TimeScale::UTC;
let (y, mm, dd, hh, min, s, nanos) =
Self::compute_gregorian(self.to_duration_in_time_scale(ts), ts);
if nanos == 0 {
write!(f, "{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02} {ts}")
} else {
write!(
f,
"{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02}.{nanos:09} {ts}"
)
}
}
}
impl fmt::LowerHex for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ts = TimeScale::TAI;
let (y, mm, dd, hh, min, s, nanos) =
Self::compute_gregorian(self.to_duration_in_time_scale(ts), ts);
if nanos == 0 {
write!(f, "{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02} {ts}")
} else {
write!(
f,
"{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02}.{nanos:09} {ts}"
)
}
}
}
impl fmt::UpperHex for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ts = TimeScale::TT;
let (y, mm, dd, hh, min, s, nanos) =
Self::compute_gregorian(self.to_duration_in_time_scale(ts), ts);
if nanos == 0 {
write!(f, "{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02} {ts}")
} else {
write!(
f,
"{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02}.{nanos:09} {ts}"
)
}
}
}
impl fmt::LowerExp for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ts = TimeScale::TDB;
let (y, mm, dd, hh, min, s, nanos) =
Self::compute_gregorian(self.to_duration_in_time_scale(ts), ts);
if nanos == 0 {
write!(f, "{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02} {ts}")
} else {
write!(
f,
"{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02}.{nanos:09} {ts}"
)
}
}
}
impl fmt::UpperExp for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ts = TimeScale::ET;
let (y, mm, dd, hh, min, s, nanos) =
Self::compute_gregorian(self.to_duration_in_time_scale(ts), ts);
if nanos == 0 {
write!(f, "{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02} {ts}")
} else {
write!(
f,
"{y:04}-{mm:02}-{dd:02}T{hh:02}:{min:02}:{s:02}.{nanos:09} {ts}"
)
}
}
}
impl fmt::Pointer for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_unix_seconds())
}
}
impl fmt::Octal for Epoch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_gpst_nanoseconds().unwrap())
}
}