DicomDate works and has doc
TODOs
change docs for time / datetime
add docs for dicomtime / dicomdatetime
write tests
@@ -2088,23 +2088,23 @@ impl PrimitiveValue {
/// Retrieve the full sequence of `DicomDate`s from this value.
///
/// # Example
- ///
/// ```
- /// # use dicom_core::value::{C, PrimitiveValue};
- /// # use smallvec::smallvec;
+ /// # use dicom_core::value::{PrimitiveValue};
+ /// # use dicom_core::dicom_value;
/// # use dicom_core::value::partial::DicomDate;
///
/// assert_eq!(
- /// PrimitiveValue::Strs(smallvec![
- /// "201410".to_string(),
- /// "2020".to_string(),
- /// ]).to_multi_dicom_date().ok(),
- /// Some(vec![
- /// DicomDate::from_ym(2014, 10),
- /// DicomDate::from_y(2020),
- /// ])
+ /// dicom_value!(Strs, ["201410", "2020", "20200101"])
+ /// .to_multi_dicom_date()
+ /// .unwrap(),
+ /// vec![
+ /// DicomDate::Month(2014, 10),
+ /// DicomDate::from_y(2020).unwrap(),
+ /// DicomDate::from_ymd(2020, 1, 1).unwrap()
+ /// ]
/// );
/// ```
+ ///
pub fn to_multi_dicom_date(&self) -> Result<Vec<DicomDate>, ConvertValueError> {
match self {
PrimitiveValue::Date(d) => d
@@ -3043,6 +3043,7 @@ fn trim_last_whitespace(x: &[u8]) -> &[u8] {
mod tests {
use super::{CastValueError, ConvertValueError, InvalidValueReadError};
use crate::dicom_value;
+ use crate::value::partial::{DicomDate, DicomDateTime, DicomTime};
use crate::value::{PrimitiveValue, ValueType};
use chrono::{FixedOffset, NaiveDate, NaiveTime, TimeZone};
use smallvec::smallvec;
@@ -3323,6 +3324,20 @@ mod tests {
));
}
+ #[test]
+ fn primitive_value_to_multi_dicom_date() {
+ assert_eq!(
+ dicom_value!(Strs, ["201410", "2020", "20200101"])
+ .to_multi_dicom_date()
+ .unwrap(),
+ vec![
+ DicomDate::Month(2014, 10),
+ DicomDate::from_y(2020).unwrap(),
+ DicomDate::from_ymd(2020, 1, 1).unwrap()
+ ]
+ );
+ }
+
#[test]
fn primitive_value_to_time() {
// trivial conversion
