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§

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

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

Retrieves a refrence to the internal date value

Retrieves a refrence to the internal time value, if present

Retrieves a refrence to the internal offset value

Retrieves a dicom encoded string representation of the value.

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

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.