pub struct DicomTime(_);
Expand description

Represents a Dicom Time value with a partial precision, where some time components may be missing.

Unlike chrono::NaiveTime, this implemenation has only 6 digit precision for fraction of a second.

DicomTime implements AsRange trait, enabling to retrieve specific time values.

Example

use chrono::NaiveTime;
use dicom_core::value::{DicomTime, AsRange};

let time = DicomTime::from_hm(12, 30)?;

assert_eq!(
    Some(time.latest()?),
    NaiveTime::from_hms_micro_opt(12, 30, 59, 999_999)
);

let milli = DicomTime::from_hms_milli(12, 30, 59, 123)?;

// value still not precise to microsecond
assert_eq!(milli.is_precise(), false);

assert_eq!(milli.to_string(), "12:30:59.123");

// for convenience, is precise enough to be retrieved as a NaiveTime
assert_eq!(
    Some(milli.to_naive_time()?),
    NaiveTime::from_hms_micro_opt(12, 30, 59, 123_000)
);

let time = DicomTime::try_from(&NaiveTime::from_hms_opt(12, 30, 59).unwrap())?;
// conversion from chrono value leads to a precise value
assert_eq!(time.is_precise(), true);

Implementations§

Constructs a new DicomTime with hour precision (HH).

Constructs a new DicomTime with hour and minute precision (HHMM).

Constructs a new DicomTime with hour, minute and second precision (HHMMSS).

Constructs a new DicomTime from an hour, minute, second and millisecond value, which leads to a (HHMMSS.FFF) precision. Millisecond cannot exceed 999.

Constructs a new DicomTime from an hour, minute, second and microsecond value, which leads to full (HHMMSS.FFFFFF) precision. Microsecond cannot exceed 999_999.

Retrievies the hour from a time as a reference

Retrievies the minute from a time as a reference

Retrievies the minute from a time as a reference

Retrievies the fraction of a second as a reference, if it has full (microsecond) precision.

Retrieves a dicom encoded string representation of the value.

Retrieves a chrono::NaiveTime if the value is precise up to the second.

Missing second fraction defaults to zero.

Trait Implementations§

Returns the earliest possible chrono value from a partial precision structure. Missing components default to 1 (days, months) or 0 (hours, minutes, …) If structure contains invalid combination of DateComponents, it fails. Read more
Returns the latest possible chrono value from a partial precision structure. If structure contains invalid combination of DateComponents, it fails. Read more
Returns a tuple of the earliest and latest possible value from a partial precision structure.
Returns a corresponding chrono value, if the partial precision structure has full accuracy.
Returns true if partial precision structure has the maximum possible accuracy. For fraction of a second, the full 6 digits are required for the value to be precise. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.