Struct dicom_core::value::partial::DicomDate
source · pub struct DicomDate(_);Expand description
Represents a Dicom Date 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 Item = NaiveDate
type Range = DateRange
source§fn earliest(&self) -> Result<NaiveDate, Error>
fn earliest(&self) -> Result<NaiveDate, 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<NaiveDate, Error>
fn latest(&self) -> Result<NaiveDate, 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<DateRange, Error>
fn range(&self) -> Result<DateRange, 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<DicomDate> for PrimitiveValue
impl From<DicomDate> for PrimitiveValue
source§impl PartialEq<DicomDate> for DicomDate
impl PartialEq<DicomDate> for DicomDate
impl Copy for DicomDate
impl StructuralPartialEq for DicomDate
Auto Trait Implementations§
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