Struct dicom_core::value::partial::DicomDateTime
source · [−]pub struct DicomDateTime { /* private fields */ }
Expand description
Represents a Dicom DateTime value with a partial precision,
where some date / 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
chrono::DateTime
values can be retrieved.
Example
use chrono::{DateTime, FixedOffset, TimeZone};
use dicom_core::value::{DicomDate, DicomTime, DicomDateTime, AsRange};
let offset = FixedOffset::east(3600);
// the least precise date-time value possible is a 'YYYY'
let dt = DicomDateTime::from_date(
DicomDate::from_y(2020)?,
offset
);
assert_eq!(
dt.earliest()?,
offset.ymd(2020, 1, 1)
.and_hms(0, 0, 0)
);
assert_eq!(
dt.latest()?,
offset.ymd(2020, 12, 31)
.and_hms_micro(23, 59, 59, 999_999)
);
let dt = DicomDateTime::try_from(&offset
.ymd(2020, 12, 31)
.and_hms(23, 59, 0)
)?;
// 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
sourceimpl DicomDateTime
impl DicomDateTime
sourcepub fn from_date(date: DicomDate, offset: FixedOffset) -> DicomDateTime
pub fn from_date(date: DicomDate, offset: FixedOffset) -> DicomDateTime
Constructs a new DicomDateTime
from a DicomDate
and a given FixedOffset
.
sourcepub fn from_date_and_time(
date: DicomDate,
time: DicomTime,
offset: FixedOffset
) -> Result<DicomDateTime, Error>
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.
sourcepub fn time(&self) -> Option<&DicomTime>
pub fn time(&self) -> Option<&DicomTime>
Retrieves a refrence to the internal time value, if present
sourcepub fn offset(&self) -> &FixedOffset
pub fn offset(&self) -> &FixedOffset
Retrieves a refrence to the internal offset value
sourceimpl DicomDateTime
impl DicomDateTime
sourcepub fn to_encoded(&self) -> String
pub fn to_encoded(&self) -> String
Retrieves a dicom encoded string representation of the value.
sourceimpl DicomDateTime
impl DicomDateTime
sourcepub fn to_chrono_datetime(self) -> Result<DateTime<FixedOffset>, Error>
pub fn to_chrono_datetime(self) -> Result<DateTime<FixedOffset>, Error>
Retrieves a chrono::DateTime<FixedOffset>
if value is precise.
Trait Implementations
sourceimpl AsRange for DicomDateTime
impl AsRange for DicomDateTime
type Item = DateTime<FixedOffset>
type Range = DateTimeRange
sourcefn earliest(&self) -> Result<DateTime<FixedOffset>, Error>
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 DateComponent
s, it fails. Read more
sourcefn latest(&self) -> Result<DateTime<FixedOffset>, Error>
fn latest(&self) -> Result<DateTime<FixedOffset>, Error>
Returns the latest possible chrono
value from a partial precision structure.
If structure contains invalid combination of DateComponent
s, it fails. Read more
sourcefn range(&self) -> Result<DateTimeRange, Error>
fn range(&self) -> Result<DateTimeRange, Error>
Returns a tuple of the earliest and latest possible value from a partial precision structure.
sourcefn exact(&self) -> Result<Self::Item, Error>
fn exact(&self) -> Result<Self::Item, Error>
Returns a corresponding chrono
value, if the partial precision structure has full accuracy.
sourcefn is_precise(&self) -> bool
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. Read more
sourceimpl Clone for DicomDateTime
impl Clone for DicomDateTime
sourcefn clone(&self) -> DicomDateTime
fn clone(&self) -> DicomDateTime
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for DicomDateTime
impl Debug for DicomDateTime
sourceimpl Display for DicomDateTime
impl Display for DicomDateTime
sourceimpl From<DicomDateTime> for PrimitiveValue
impl From<DicomDateTime> for PrimitiveValue
sourcefn from(value: DicomDateTime) -> Self
fn from(value: DicomDateTime) -> Self
Converts to this type from the input type.
sourceimpl PartialEq<DicomDateTime> for DicomDateTime
impl PartialEq<DicomDateTime> for DicomDateTime
sourcefn eq(&self, other: &DicomDateTime) -> bool
fn eq(&self, other: &DicomDateTime) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &DicomDateTime) -> bool
fn ne(&self, other: &DicomDateTime) -> bool
This method tests for !=
.
sourceimpl Precision for DicomDateTime
impl Precision for DicomDateTime
fn precision(&self) -> DateComponent
sourceimpl TryFrom<&DateTime<FixedOffset>> for DicomDateTime
impl TryFrom<&DateTime<FixedOffset>> for DicomDateTime
impl Copy for DicomDateTime
impl StructuralPartialEq for DicomDateTime
Auto Trait Implementations
impl RefUnwindSafe for DicomDateTime
impl Send for DicomDateTime
impl Sync for DicomDateTime
impl Unpin for DicomDateTime
impl UnwindSafe for DicomDateTime
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more