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
impl DicomDateTime
Sourcepub fn from_date_with_time_zone(
date: DicomDate,
time_zone: FixedOffset,
) -> DicomDateTime
pub fn from_date_with_time_zone( date: DicomDate, time_zone: FixedOffset, ) -> DicomDateTime
Constructs a new DicomDateTime
from a DicomDate
and a timezone FixedOffset
.
Sourcepub fn from_date(date: DicomDate) -> DicomDateTime
pub fn from_date(date: DicomDate) -> DicomDateTime
Constructs a new DicomDateTime
from a DicomDate
.
Sourcepub fn from_date_and_time(
date: DicomDate,
time: DicomTime,
) -> Result<DicomDateTime, Error>
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.
Sourcepub fn from_date_and_time_with_time_zone(
date: DicomDate,
time: DicomTime,
time_zone: FixedOffset,
) -> Result<DicomDateTime, Error>
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.
Sourcepub fn time(&self) -> Option<&DicomTime>
pub fn time(&self) -> Option<&DicomTime>
Retrieves a reference to the internal time value, if present
Sourcepub fn time_zone(&self) -> Option<&FixedOffset>
pub fn time_zone(&self) -> Option<&FixedOffset>
Retrieves a reference to the internal time-zone value, if present
Sourcepub fn has_time_zone(&self) -> bool
pub fn has_time_zone(&self) -> bool
Returns true, if the DicomDateTime
contains a time-zone
Source§impl DicomDateTime
impl DicomDateTime
Sourcepub fn to_encoded(&self) -> String
pub fn to_encoded(&self) -> String
Retrieves a dicom encoded string representation of the value.
Source§impl DicomDateTime
impl DicomDateTime
Sourcepub fn to_precise_datetime(&self) -> Result<PreciseDateTime, Error>
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.
pub fn to_chrono_datetime(self) -> Result<DateTime<FixedOffset>, Error>
to_precise_date_time()
Trait Implementations§
Source§impl AsRange for DicomDateTime
impl AsRange for DicomDateTime
type PreciseValue = PreciseDateTime
type Range = DateTimeRange
Source§fn is_precise(&self) -> bool
fn is_precise(&self) -> bool
Source§fn earliest(&self) -> Result<Self::PreciseValue, Error>
fn earliest(&self) -> Result<Self::PreciseValue, Error>
DateComponent
s, it fails.Source§fn latest(&self) -> Result<Self::PreciseValue, Error>
fn latest(&self) -> Result<Self::PreciseValue, Error>
DateComponent
s, it fails.Source§impl Clone for DicomDateTime
impl Clone for DicomDateTime
Source§fn clone(&self) -> DicomDateTime
fn clone(&self) -> DicomDateTime
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DicomDateTime
impl Debug for DicomDateTime
Source§impl Display for DicomDateTime
impl Display for DicomDateTime
Source§impl From<DicomDateTime> for PrimitiveValue
impl From<DicomDateTime> for PrimitiveValue
Source§fn from(value: DicomDateTime) -> Self
fn from(value: DicomDateTime) -> Self
Source§impl<I, P> From<DicomDateTime> for Value<I, P>
impl<I, P> From<DicomDateTime> for Value<I, P>
Source§fn from(value: DicomDateTime) -> Self
fn from(value: DicomDateTime) -> Self
Converts the DICOM date-time into a primitive value.
Source§impl FromStr for DicomDateTime
impl FromStr for DicomDateTime
Source§impl PartialEq for DicomDateTime
impl PartialEq for DicomDateTime
Source§impl TryFrom<&DateTime<FixedOffset>> for DicomDateTime
impl TryFrom<&DateTime<FixedOffset>> for DicomDateTime
Source§impl TryFrom<&NaiveDateTime> for DicomDateTime
impl TryFrom<&NaiveDateTime> for DicomDateTime
impl Copy for DicomDateTime
impl StructuralPartialEq for DicomDateTime
Auto Trait Implementations§
impl Freeze for DicomDateTime
impl RefUnwindSafe for DicomDateTime
impl Send for DicomDateTime
impl Sync for DicomDateTime
impl Unpin for DicomDateTime
impl UnwindSafe for DicomDateTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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