pub struct TimeParts {Show 19 fields
pub year: Option<i64>,
pub month: Option<u8>,
pub day: Option<u8>,
pub hour: Option<u8>,
pub minute: Option<u8>,
pub second: Option<u8>,
pub attos: Option<u64>,
pub offset: Option<Offset>,
pub iana_name: Option<AsciiStr<49>>,
pub is_leap_second: bool,
pub scale: Scale,
pub weekday: Option<Weekday>,
pub day_of_year: Option<u16>,
pub iso_week_year: Option<i64>,
pub iso_week: Option<u8>,
pub week_sun: Option<u8>,
pub week_mon: Option<u8>,
pub meridiem: Option<Meridiem>,
pub unix_timestamp_seconds: Option<i64>,
}Fields§
§year: Option<i64>§month: Option<u8>§day: Option<u8>§hour: Option<u8>§minute: Option<u8>§second: Option<u8>§attos: Option<u64>§offset: Option<Offset>§iana_name: Option<AsciiStr<49>>§is_leap_second: bool§scale: Scale§weekday: Option<Weekday>§day_of_year: Option<u16>§iso_week_year: Option<i64>§iso_week: Option<u8>§week_sun: Option<u8>§week_mon: Option<u8>§meridiem: Option<Meridiem>§unix_timestamp_seconds: Option<i64>Implementations§
Source§impl TimeParts
impl TimeParts
Sourcepub fn days_since_1958_to_gregorian(days_since_epoch: i64) -> (i64, u8, u8)
pub fn days_since_1958_to_gregorian(days_since_epoch: i64) -> (i64, u8, u8)
Converts days since 1958-01-01 (midnight UTC/TAI) into Gregorian date. Pure integer arithmetic matching the CCSDS 301.0-B-4 Level 1 epoch.
Sourcepub fn gregorian_to_days_since_1958(year: i64, month: u8, day: u8) -> i64
pub fn gregorian_to_days_since_1958(year: i64, month: u8, day: u8) -> i64
Exact inverse of days_since_1958_to_gregorian.
Sourcepub fn from_ccsds_ccs(input: &[u8]) -> Result<TimeParts, DtErr>
pub fn from_ccsds_ccs(input: &[u8]) -> Result<TimeParts, DtErr>
Parses a CCSDS Calendar Segmented Time Code (CCS) into TimeParts.
Implements CCSDS 301.0-B-4 §3.4 (Level 1 only).
This function accepts a single-byte P-field followed by a BCD-encoded T-field. It supports both calendar variants:
- Month/Day format (most common)
- Day-of-Year format
§P-field
- Must not have the extension bit set (only 1-byte P-fields are supported).
- Code ID must be
101. - Subsecond resolution: 0 to 6 BCD octets (0–12 decimal digits).
§T-field
- Year is encoded as 4 BCD digits (0001–9999).
- Time of day uses BCD with leap second support (
second == 60). - When a leap second is present,
secondis normalized to 59 andis_leap_secondis set totruein the returnedTimeParts.
§Epoch
1958-01-01 00:00:00 UTC (identical to CDS).
§Errors
Returns an error if the P-field is extended, the Code ID is wrong, BCD digits are invalid, field lengths are insufficient, or any component (month, day, DOY, hour, minute, second) is out of range.
The resulting TimeParts has scale = UTC.
Sourcepub fn from_ccsds_c(input: &[u8]) -> Result<TimeParts, DtErr>
pub fn from_ccsds_c(input: &[u8]) -> Result<TimeParts, DtErr>
Parses a CCSDS Unsegmented Time Code (CUC) into TimeParts.
Implements CCSDS 301.0-B-4 §3.2 (Level 1), including full support for the extended 2-byte P-field defined in Issue 4.
§P-field
- Supports both 1-byte and 2-byte P-fields.
- Code ID must be
001(1958-01-01 TAI epoch). - Coarse time: 1–7 octets total.
- Fractional time: 0–10 octets total.
- P-fields longer than 2 bytes are rejected.
§T-field
- Coarse time is interpreted as seconds since the 1958 TAI epoch.
- Fractional time is converted to attoseconds using exact integer scaling
(
value / 2^(8·n_frac)).
§Epoch
1958-01-01 00:00:00 TAI.
§Errors
Returns an error for empty input, insufficient length, invalid Code ID, unsupported further P-field extensions, or malformed T-field data.
The resulting TimeParts has scale = TAI.
Sourcepub fn from_ccsds_d(input: &[u8]) -> Result<TimeParts, DtErr>
pub fn from_ccsds_d(input: &[u8]) -> Result<TimeParts, DtErr>
Parses a CCSDS Day Segmented Time Code (CDS) into TimeParts.
Implements CCSDS 301.0-B-4 §3.3 (Level 1).
§P-field
- Supports optional 2-byte P-field.
- Code ID must be
100. - Epoch bit must be
0(1958-01-01 UTC epoch only). - Day count: 2 or 3 bytes.
- Sub-millisecond resolution: none, 2 bytes (µs), or 4 bytes (2⁻³² of a ms).
§T-field
- Day count is days since 1958-01-01 UTC.
- Milliseconds since midnight are always 4 bytes.
- Sub-millisecond field (if present) is converted to attoseconds.
§Leap Second Handling
This implementation correctly supports leap seconds. When millis_of_day
represents 23:59:60 (i.e. ≥ 86,400,000 ms), second is set to 60 and
is_leap_second is set to true in the returned TimeParts.
§Epoch
1958-01-01 00:00:00 UTC.
§Errors
Returns an error for empty input, wrong Code ID, non-Level-1 epoch, unsupported sub-millisecond code, insufficient length, or invalid data.
The resulting TimeParts has scale = UTC.
Sourcepub fn from_ccsds_bin(input: &[u8]) -> Result<TimeParts, DtErr>
pub fn from_ccsds_bin(input: &[u8]) -> Result<TimeParts, DtErr>
Auto-detects and parses a CCSDS binary time code (CUC, CDS, or CCS).
Examines the Code ID in the first P-field byte and dispatches to the appropriate parser:
001→ [from_ccsds_c] (CUC)100→ [from_ccsds_d] (CDS)101→ [from_ccsds_ccs] (CCS)
This is a convenience wrapper. For stricter control or when the format
is known in advance, prefer calling the specific from_ccsds_* function directly.
§Errors
Returns an error if the input is empty or the Code ID is not one of the three recognized Level 1 values.
Source§impl TimeParts
impl TimeParts
Sourcepub fn from_ccsds_str(input: &str) -> Result<Self, DtErr>
pub fn from_ccsds_str(input: &str) -> Result<Self, DtErr>
Generalized CCSDS ASCII Time Code parser (A or B variant).
Handles both calendar (%Y-%m-%d) and day-of-year (%Y-%j) formats.
All time components after the date portion are optional.
Source§impl TimeParts
impl TimeParts
Sourcepub fn to_ccsds_c(
&self,
n_coarse: u8,
n_frac: u8,
extension: bool,
) -> Result<([u8; 32], usize), DtErr>
pub fn to_ccsds_c( &self, n_coarse: u8, n_frac: u8, extension: bool, ) -> Result<([u8; 32], usize), DtErr>
Formats this TimeParts as a CCSDS C (CUC) binary time code.
Fully configurable for round-tripping with [from_ccsds_c].
Conforms to CCSDS 301.0-B-4 §3.2 (Level 1), including full support for the
extended P-field (second octet) when n_coarse > 4 or n_frac > 3.
§Parameters
n_coarse: 1–7 (number of coarse-time octets)n_frac: 0–10 (number of fractional octets)extension: advisory flag (ignored when larger sizes force the second octet)
Sourcepub fn to_ccsds_d(
&self,
n_day: u8,
sub_ms_code: u8,
extension: bool,
) -> Result<([u8; 32], usize), DtErr>
pub fn to_ccsds_d( &self, n_day: u8, sub_ms_code: u8, extension: bool, ) -> Result<([u8; 32], usize), DtErr>
Formats this TimeParts as a CCSDS D (CDS) binary time code.
Fully configurable for round-tripping with [from_ccsds_d].
Conforms to CCSDS 301.0-B-4 §3.3 (Level 1): UTC day count + ms-of-day since 1958-01-01 UTC.
Sourcepub fn to_ccsds_ccs(
&self,
use_doy: bool,
n_subsec: u8,
) -> Result<([u8; 14], usize), DtErr>
pub fn to_ccsds_ccs( &self, use_doy: bool, n_subsec: u8, ) -> Result<([u8; 14], usize), DtErr>
Formats this TimeParts as a CCSDS CCS (Calendar Segmented Time Code).
Implements CCSDS 301.0-B-4 §3.4 (Level 1 only).
§Parameters
use_doy:false= Month/Day variant (most common),true= Day-of-Year variantn_subsec: Number of subsecond BCD octets (0–6). Each octet holds 2 decimal digits.
§Returns
(buffer, written_len) — the P-field + T-field (big-endian BCD).
§Precision & Rounding
Fractional seconds are rounded to the nearest representable value at the chosen precision
(exactly as to_ccsds_d does for milliseconds).
Sourcepub fn to_ccsds_bin(&self) -> Result<([u8; 32], usize), DtErr>
pub fn to_ccsds_bin(&self) -> Result<([u8; 32], usize), DtErr>
Convenience method that automatically selects the most appropriate
CCSDS binary time code based on this TimeParts’s [Scale].
§Automatic selection (matches common mission practice)
Scale::TAI→ CUC (4 coarse + 4 fractional bytes)- Any other
Scale(UTC, TT, GPS, TCG, …) → converted to UTC and uses CDS (2 day bytes + 4 ms bytes + 2-byte sub-ms)