pub struct DicomDate(/* private fields */);Expand description
Represents a Dicom date (DA) value with a partial precision, where some date components may be missing.
Unlike chrono::NaiveDate, it does not allow for negative years.
DicomDate implements AsRange trait, enabling to retrieve specific
date values.
§Example
use chrono::NaiveDate;
use dicom_core::value::{DicomDate, AsRange};
let date = DicomDate::from_y(1492)?;
assert_eq!(
Some(date.latest()?),
NaiveDate::from_ymd_opt(1492,12,31)
);
let date = DicomDate::try_from(&NaiveDate::from_ymd_opt(1900, 5, 3).unwrap())?;
// conversion from chrono value leads to a precise value
assert_eq!(date.is_precise(), true);
assert_eq!(date.to_string(), "1900-05-03");Implementations§
Source§impl DicomDate
impl DicomDate
Sourcepub fn from_y(year: u16) -> Result<DicomDate, Error>
pub fn from_y(year: u16) -> Result<DicomDate, Error>
Constructs a new DicomDate with year precision
(YYYY)
Sourcepub fn from_ym(year: u16, month: u8) -> Result<DicomDate, Error>
pub fn from_ym(year: u16, month: u8) -> Result<DicomDate, Error>
Constructs a new DicomDate with year and month precision
(YYYYMM)
Sourcepub fn from_ymd(year: u16, month: u8, day: u8) -> Result<DicomDate, Error>
pub fn from_ymd(year: u16, month: u8, day: u8) -> Result<DicomDate, Error>
Constructs a new DicomDate with a year, month and day precision
(YYYYMMDD)
pub fn year(&self) -> &u16
pub fn month(&self) -> Option<&u8>
pub fn day(&self) -> Option<&u8>
Trait Implementations§
Source§impl AsRange for DicomDate
impl AsRange for DicomDate
type PreciseValue = NaiveDate
type Range = DateRange
Source§fn is_precise(&self) -> bool
fn is_precise(&self) -> bool
returns true if value has all possible date / time components
Source§fn earliest(&self) -> Result<Self::PreciseValue, Error>
fn earliest(&self) -> Result<Self::PreciseValue, Error>
Returns the earliest possible 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<Self::PreciseValue, Error>
fn latest(&self) -> Result<Self::PreciseValue, Error>
Returns the latest possible value from a partial precision structure.
If structure contains invalid combination of
DateComponents, it fails.Source§impl From<DicomDate> for PrimitiveValue
impl From<DicomDate> for PrimitiveValue
impl Copy for DicomDate
impl StructuralPartialEq for DicomDate
Auto Trait Implementations§
impl Freeze for DicomDate
impl RefUnwindSafe for DicomDate
impl Send for DicomDate
impl Sync for DicomDate
impl Unpin for DicomDate
impl UnwindSafe for DicomDate
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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