dicom_core::value::partial

Struct DicomDateTime

Source
pub struct DicomDateTime { /* private fields */ }
Expand description

Represents a Dicom date-time (DT) value with a partial precision, where some date or time components may be missing.

DicomDateTime is always internally represented by a DicomDate. The DicomTime and a timezone FixedOffset values are optional.

It implements AsRange trait, which serves to retrieve a PreciseDateTime from values with missing components.

§Example

use chrono::{DateTime, FixedOffset, TimeZone, NaiveDateTime, NaiveDate, NaiveTime};
use dicom_core::value::{DicomDate, DicomTime, DicomDateTime, AsRange, PreciseDateTime};

let offset = FixedOffset::east_opt(3600).unwrap();

// lets create the least precise date-time value possible 'YYYY' and make it time-zone aware
let dt = DicomDateTime::from_date_with_time_zone(
    DicomDate::from_y(2020)?,
    offset
);
// the earliest possible value is output as a [PreciseDateTime]
assert_eq!(
    dt.earliest()?,
    PreciseDateTime::TimeZone(
    offset.from_local_datetime(&NaiveDateTime::new(
        NaiveDate::from_ymd_opt(2020, 1, 1).unwrap(),
        NaiveTime::from_hms_opt(0, 0, 0).unwrap()
    )).single().unwrap())
);
assert_eq!(
    dt.latest()?,
    PreciseDateTime::TimeZone(
    offset.from_local_datetime(&NaiveDateTime::new(
        NaiveDate::from_ymd_opt(2020, 12, 31).unwrap(),
        NaiveTime::from_hms_micro_opt(23, 59, 59, 999_999).unwrap()
    )).single().unwrap())
);

let chrono_datetime = offset.from_local_datetime(&NaiveDateTime::new(
        NaiveDate::from_ymd_opt(2020, 12, 31).unwrap(),
        NaiveTime::from_hms_opt(23, 59, 0).unwrap()
    )).unwrap();

let dt = DicomDateTime::try_from(&chrono_datetime)?;
// conversion from chrono value leads to a precise value
assert_eq!(dt.is_precise(), true);

assert_eq!(dt.to_string(), "2020-12-31 23:59:00.0 +01:00");

Implementations§

Source§

impl DicomDateTime

Source

pub fn from_date_with_time_zone( date: DicomDate, time_zone: FixedOffset, ) -> DicomDateTime

Constructs a new DicomDateTime from a DicomDate and a timezone FixedOffset.

Source

pub fn from_date(date: DicomDate) -> DicomDateTime

Constructs a new DicomDateTime from a DicomDate .

Source

pub fn from_date_and_time( date: DicomDate, time: DicomTime, ) -> Result<DicomDateTime, Error>

Constructs a new DicomDateTime from a DicomDate and a DicomTime, providing that DicomDate is precise.

Source

pub fn from_date_and_time_with_time_zone( date: DicomDate, time: DicomTime, time_zone: FixedOffset, ) -> Result<DicomDateTime, Error>

Constructs a new DicomDateTime from a DicomDate, DicomTime and a timezone FixedOffset, providing that DicomDate is precise.

Source

pub fn date(&self) -> &DicomDate

Retrieves a reference to the internal date value

Source

pub fn time(&self) -> Option<&DicomTime>

Retrieves a reference to the internal time value, if present

Source

pub fn time_zone(&self) -> Option<&FixedOffset>

Retrieves a reference to the internal time-zone value, if present

Source

pub fn has_time_zone(&self) -> bool

Returns true, if the DicomDateTime contains a time-zone

Source

pub fn offset(&self)

👎Deprecated since 0.7.0: Use time_zone instead

Retrieves a reference to the internal offset value

Source§

impl DicomDateTime

Source

pub fn to_encoded(&self) -> String

Retrieves a dicom encoded string representation of the value.

Source§

impl DicomDateTime

Source

pub fn to_precise_datetime(&self) -> Result<PreciseDateTime, Error>

Retrieves a PreciseDateTime from a date-time value. If the date-time value is not precise or the conversion leads to ambiguous results, it fails.

Source

pub fn to_chrono_datetime(self) -> Result<DateTime<FixedOffset>, Error>

👎Deprecated since 0.7.0: Use to_precise_date_time()

Trait Implementations§

Source§

impl AsRange for DicomDateTime

Source§

type PreciseValue = PreciseDateTime

Source§

type Range = DateTimeRange

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 DicomDateTime

Source§

fn clone(&self) -> DicomDateTime

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 DicomDateTime

Source§

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

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

impl Display for DicomDateTime

Source§

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

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

impl From<DicomDateTime> for PrimitiveValue

Source§

fn from(value: DicomDateTime) -> Self

Converts to this type from the input type.
Source§

impl<I, P> From<DicomDateTime> for Value<I, P>

Source§

fn from(value: DicomDateTime) -> Self

Converts the DICOM date-time into a primitive value.

Source§

impl FromStr for DicomDateTime

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for DicomDateTime

Source§

fn eq(&self, other: &DicomDateTime) -> 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<&DateTime<FixedOffset>> for DicomDateTime

Source§

type Error = Error

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

fn try_from(dt: &DateTime<FixedOffset>) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<&NaiveDateTime> for DicomDateTime

Source§

type Error = Error

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

fn try_from(dt: &NaiveDateTime) -> Result<Self, Error>

Performs the conversion.
Source§

impl Copy for DicomDateTime

Source§

impl StructuralPartialEq for DicomDateTime

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.