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

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

DicomDateTime is always internally represented by a DicomDate and optionally by a DicomTime.

It implements AsRange trait and also holds a FixedOffset value, from which corresponding datetime values can be retrieved.

Example

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

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

// the least precise date-time value possible is a 'YYYY'
let dt = DicomDateTime::from_date(
    DicomDate::from_y(2020)?,
    offset
);
assert_eq!(
    Some(dt.earliest()?),
    offset.from_local_datetime(&NaiveDateTime::new(
        NaiveDate::from_ymd_opt(2020, 1, 1).unwrap(),
        NaiveTime::from_hms_opt(0, 0, 0).unwrap()
    )).single()
);
assert_eq!(
    Some(dt.latest()?),
    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()
);

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(date: DicomDate, offset: FixedOffset) -> DicomDateTime

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

source

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

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

source

pub fn date(&self) -> &DicomDate

Retrieves a refrence to the internal date value

source

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

Retrieves a refrence to the internal time value, if present

source

pub fn offset(&self) -> &FixedOffset

Retrieves a refrence 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_chrono_datetime(self) -> Result<DateTime<FixedOffset>, Error>

Retrieves a chrono::DateTime<FixedOffset> if value is precise.

Trait Implementations§

source§

impl AsRange for DicomDateTime

§

type Item = DateTime<FixedOffset>

§

type Range = DateTimeRange

source§

fn earliest(&self) -> Result<DateTime<FixedOffset>, Error>

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.
source§

fn latest(&self) -> Result<DateTime<FixedOffset>, Error>

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

fn range(&self) -> Result<DateTimeRange, Error>

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

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

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

fn is_precise(&self) -> bool

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.
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 PartialEq<DicomDateTime> for DicomDateTime

source§

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

source§

impl TryFrom<&DateTime<FixedOffset>> for DicomDateTime

§

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 Copy for DicomDateTime

source§

impl StructuralPartialEq for DicomDateTime

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere 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 Twhere 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 Twhere 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 Twhere 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.