pub struct DicomDate(_);
Expand description
Represents a Dicom Date value with a partial precision, where some date components may be missing.
Unlike Rust’s chrono::NaiveDate
, it does not allow for negative years.
DicomDate
implements AsRange
trait, enabling to retrieve specific
chrono::NaiveDate
values.
Example
use chrono::NaiveDate;
use dicom_core::value::{DicomDate, AsRange};
let date = DicomDate::from_y(1492)?;
assert_eq!(
date.latest()?,
NaiveDate::from_ymd(1492,12,31)
);
let date = DicomDate::try_from(&NaiveDate::from_ymd(1900, 5, 3))?;
// conversion from chrono value leads to a precise value
assert_eq!(date.is_precise(), true);
assert_eq!(date.to_string(), "1900-05-03");
Implementations
sourceimpl 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>
sourceimpl DicomDate
impl DicomDate
sourcepub fn to_encoded(&self) -> String
pub fn to_encoded(&self) -> String
Retrieves a dicom encoded string representation of the value.
Trait Implementations
sourceimpl AsRange for DicomDate
impl AsRange for DicomDate
type Item = NaiveDate
type Range = DateRange
sourcefn 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 DateComponent
s, it fails. Read more
sourcefn 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 DateComponent
s, it fails. Read more
sourcefn 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.
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 From<DicomDate> for PrimitiveValue
impl From<DicomDate> for PrimitiveValue
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
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