pub struct DicomTime(/* private fields */);
Expand description
Represents a Dicom time (TM) value with a partial precision, where some time components may be missing.
Unlike chrono::NaiveTime, this implementation 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 the precision HHMMSS.FFF
. Millisecond cannot exceed 999
.
Sourcepub fn from_hms_micro(
hour: u8,
minute: u8,
second: u8,
microsecond: u32,
) -> Result<DicomTime, Error>
pub fn from_hms_micro( hour: u8, minute: u8, second: u8, microsecond: u32, ) -> Result<DicomTime, Error>
Constructs a new DicomTime
from an hour, minute, second and microsecond value,
which leads to the full precision HHMMSS.FFFFFF
.
Microsecond cannot exceed 999_999
.
Instead, leap seconds can be represented by setting second
to 60.
Trait Implementations§
Source§impl AsRange for DicomTime
impl AsRange for DicomTime
type PreciseValue = NaiveTime
type Range = TimeRange
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 From<DicomTime> for PrimitiveValue
impl From<DicomTime> for PrimitiveValue
impl Copy for DicomTime
impl StructuralPartialEq for DicomTime
Auto Trait Implementations§
impl Freeze for DicomTime
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
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