dicom_core::value::partial

Struct 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 implementation 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 the precision HHMMSS.FFF. 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 the full precision HHMMSS.FFFFFF.

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

Source

pub fn hour(&self) -> &u8

Retrieves the hour from a time as a reference

Source

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

Retrieves the minute from a time as a reference

Source

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

Retrieves the minute from a time as a reference

Source

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

Retrieves 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

Source§

type PreciseValue = NaiveTime

Source§

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<I, P> From<DicomTime> for Value<I, P>

Source§

fn from(value: DicomTime) -> Self

Converts the DICOM time into a primitive value.

Source§

impl PartialEq for DicomTime

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 TryFrom<&NaiveTime> for DicomTime

Source§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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

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.