Struct dicom_core::value::partial::DicomTime

source ·
pub struct DicomTime(/* private fields */);
Expand description

Represents a Dicom time (TM) 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§

source§

impl DicomTime

source

pub fn from_h(hour: u8) -> Result<DicomTime, Error>

Constructs a new DicomTime with hour precision (HH).

source

pub fn from_hm(hour: u8, minute: u8) -> Result<DicomTime, Error>

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

source

pub fn from_hms(hour: u8, minute: u8, second: u8) -> Result<DicomTime, Error>

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

source

pub fn from_hms_milli( hour: u8, minute: u8, second: u8, millisecond: u32 ) -> Result<DicomTime, Error>

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

source

pub fn from_hms_micro( hour: u8, minute: u8, second: u8, microsecond: u32 ) -> Result<DicomTime, Error>

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

Microsecond cannot exceed 999_999. Instead, leap seconds can be represented by setting second to 60.

source

pub fn hour(&self) -> &u8

Retrievies the hour from a time as a reference

source

pub fn minute(&self) -> Option<&u8>

Retrievies the minute from a time as a reference

source

pub fn second(&self) -> Option<&u8>

Retrievies the minute from a time as a reference

source

pub fn fraction(&self) -> Option<&u32>

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

source§

impl DicomTime

source

pub fn to_encoded(&self) -> String

Retrieves a dicom encoded string representation of the value.

source§

impl DicomTime

source

pub fn to_naive_time(self) -> Result<NaiveTime, Error>

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

Missing second fraction defaults to zero.

Trait Implementations§

source§

impl AsRange for DicomTime

§

type PreciseValue = NaiveTime

§

type Range = TimeRange

source§

fn is_precise(&self) -> bool

returns true if value has all possible date / time components
source§

fn earliest(&self) -> Result<Self::PreciseValue, Error>

Returns the earliest possible 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.
source§

fn latest(&self) -> Result<Self::PreciseValue, Error>

Returns the latest possible value from a partial precision structure. If structure contains invalid combination of DateComponents, it fails.
source§

fn range(&self) -> Result<Self::Range, Error>

Returns a tuple of the earliest and latest possible value from a partial precision structure.
source§

fn exact(&self) -> Result<Self::PreciseValue, Error>

Returns a corresponding precise value, if the partial precision structure has full accuracy.
source§

impl Clone for DicomTime

source§

fn clone(&self) -> DicomTime

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for DicomTime

source§

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

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

impl Display for DicomTime

source§

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

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

impl From<DicomTime> for PrimitiveValue

source§

fn from(value: DicomTime) -> Self

Converts to this type from the input type.
source§

impl PartialEq for DicomTime

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&NaiveTime> for DicomTime

§

type Error = Error

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

fn try_from(time: &NaiveTime) -> Result<Self, Error>

Performs the conversion.
source§

impl Copy for DicomTime

source§

impl StructuralPartialEq for DicomTime

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.