Skip to main content

TimeParts

Struct TimeParts 

Source
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

Source

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.

Source

pub fn gregorian_to_days_since_1958(year: i64, month: u8, day: u8) -> i64

Exact inverse of days_since_1958_to_gregorian.

Source

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, second is normalized to 59 and is_leap_second is set to true in the returned TimeParts.
§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.

Source

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.

Source

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.

Source

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

Source

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

Source

pub fn from_str( fmt: &str, input: &str, inp_can_end_before_fmt: bool, fmt_can_end_before_inp: bool, allow_partial_date: bool, ) -> Result<TimeParts, DtErr>

Source

pub fn finish(&mut self, allow_partial_date: bool) -> Result<&mut Self, DtErr>

Source§

impl TimeParts

Source

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)
Source

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.

Source

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 variant
  • n_subsec: Number of subsecond BCD octets (06). 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).

Source

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::TAICUC (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)
Source§

impl TimeParts

Source

pub fn to_time_point(&self) -> Result<Dt, DtErr>

Source§

impl TimeParts

Source

pub fn new_utc() -> Self

Source

pub fn set_iana_name(&mut self, name: Option<&str>) -> &mut Self

Sets the IANA timezone name safely.

Uses AsciiStr::try_from_str internally. If the name is non-ASCII or longer than 49 bytes it is silently dropped (no panics).

Trait Implementations§

Source§

impl Clone for TimeParts

Source§

fn clone(&self) -> TimeParts

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeParts

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TimeParts

Source§

fn default() -> TimeParts

Returns the “default value” for a type. Read more
Source§

impl PartialEq for TimeParts

Source§

fn eq(&self, other: &TimeParts) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TimeParts

Source§

impl StructuralPartialEq for TimeParts

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.