Skip to main content

deep_time/time_parts/
to_str_ccsds.rs

1use crate::{DtErr, TimeParts};
2use alloc::string::String;
3
4impl TimeParts {
5    /// Returns this instant as a **CCSDS ASCII Time Code** (calendar variant A).
6    ///
7    /// Example: `"2025-04-17T14:30:45.123456789Z"`
8    ///
9    /// - Uses `T` separator and trailing `Z`.
10    /// - Fractional seconds are trimmed (no trailing zeros, no dot if zero).
11    /// - Round-trips with `Dt::from_str_ccsds` / `TimeParts::from_str_ccsds`.
12    #[inline]
13    pub fn to_str_ccsds(&self) -> Result<String, DtErr> {
14        self.to_dt()?.to_str_ccsds(self.scale)
15    }
16
17    /// Same as [`to_str_ccsds`] but lets you control the maximum number of fractional digits (0–18).
18    pub fn to_str_ccsds_nf(&self, max_precision: usize) -> Result<String, DtErr> {
19        self.to_dt()?.to_str_ccsds_nf(self.scale, max_precision)
20    }
21
22    /// Returns this instant as a **CCSDS ASCII Time Code B** (day-of-year variant).
23    ///
24    /// Example: `"2025-107T14:30:45.123456789Z"`
25    #[inline]
26    pub fn to_ccsds_doy_str(&self) -> Result<String, DtErr> {
27        self.to_dt()?.to_ccsds_doy_str_nf(self.scale, 18)
28    }
29
30    /// Same as [`to_ccsds_doy_str`] but with configurable fractional precision.
31    pub fn to_ccsds_doy_str_nf(&self, max_precision: usize) -> Result<String, DtErr> {
32        self.to_dt()?.to_ccsds_doy_str_nf(self.scale, max_precision)
33    }
34}