Struct dicom_core::value::partial::DicomTime
source · pub struct DicomTime(_);Expand description
Represents a Dicom Time value with a partial precision, where some time components may be missing.
Unlike chrono::NaiveTime, this implemenation has only 6 digit precision for fraction of a second.
DicomTime implements AsRange trait, enabling to retrieve specific
time values.
Example
use chrono::NaiveTime;
use dicom_core::value::{DicomTime, AsRange};
let time = DicomTime::from_hm(12, 30)?;
assert_eq!(
Some(time.latest()?),
NaiveTime::from_hms_micro_opt(12, 30, 59, 999_999)
);
let milli = DicomTime::from_hms_milli(12, 30, 59, 123)?;
// value still not precise to microsecond
assert_eq!(milli.is_precise(), false);
assert_eq!(milli.to_string(), "12:30:59.123");
// for convenience, is precise enough to be retrieved as a NaiveTime
assert_eq!(
Some(milli.to_naive_time()?),
NaiveTime::from_hms_micro_opt(12, 30, 59, 123_000)
);
let time = DicomTime::try_from(&NaiveTime::from_hms_opt(12, 30, 59).unwrap())?;
// conversion from chrono value leads to a precise value
assert_eq!(time.is_precise(), true);
Implementations§
source§impl DicomTime
impl DicomTime
sourcepub fn from_h(hour: u8) -> Result<DicomTime, Error>
pub fn from_h(hour: u8) -> Result<DicomTime, Error>
Constructs a new DicomTime with hour precision
(HH).
sourcepub fn from_hm(hour: u8, minute: u8) -> Result<DicomTime, Error>
pub fn from_hm(hour: u8, minute: u8) -> Result<DicomTime, Error>
Constructs a new DicomTime with hour and minute precision
(HHMM).
sourcepub fn from_hms(hour: u8, minute: u8, second: u8) -> Result<DicomTime, Error>
pub fn from_hms(hour: u8, minute: u8, second: u8) -> Result<DicomTime, Error>
Constructs a new DicomTime with hour, minute and second precision
(HHMMSS).
sourcepub fn from_hms_milli(
hour: u8,
minute: u8,
second: u8,
millisecond: u32
) -> Result<DicomTime, Error>
pub fn from_hms_milli( hour: u8, minute: u8, second: u8, millisecond: u32 ) -> Result<DicomTime, Error>
Constructs a new DicomTime from an hour, minute, second and millisecond value,
which leads to a (HHMMSS.FFF) precision. Millisecond cannot exceed 999.
Trait Implementations§
source§impl AsRange for DicomTime
impl AsRange for DicomTime
type Item = NaiveTime
type Range = TimeRange
source§fn earliest(&self) -> Result<NaiveTime, Error>
fn earliest(&self) -> Result<NaiveTime, 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<NaiveTime, Error>
fn latest(&self) -> Result<NaiveTime, 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<TimeRange, Error>
fn range(&self) -> Result<TimeRange, Error>
Returns a tuple of the earliest and latest possible value from a partial precision structure.
source§fn 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.source§fn 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.source§impl From<DicomTime> for PrimitiveValue
impl From<DicomTime> for PrimitiveValue
source§impl PartialEq<DicomTime> for DicomTime
impl PartialEq<DicomTime> for DicomTime
impl Copy for DicomTime
impl StructuralPartialEq for DicomTime
Auto Trait Implementations§
impl RefUnwindSafe for DicomTime
impl Send for DicomTime
impl Sync for DicomTime
impl Unpin for DicomTime
impl UnwindSafe for DicomTime
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
Mutably borrows from an owned value. Read more