pub fn parse_datetime_partial(buf: &[u8]) -> Result<DicomDateTime, Error>
Expand description
Decode the text from the byte slice into a DicomDateTime
value,
which allows for missing Date / Time components.
This is the underlying implementation of FromStr
for DicomDateTime
.
ยงExample
use dicom_core::value::{DicomDate, DicomDateTime, DicomTime, PreciseDateTime};
use chrono::Datelike;
let input = "20240201123456.000305";
let dt = parse_datetime_partial(input.as_bytes())?;
assert_eq!(
dt,
DicomDateTime::from_date_and_time(
DicomDate::from_ymd(2024, 2, 1).unwrap(),
DicomTime::from_hms_micro(12, 34, 56, 305).unwrap(),
)?
);
// reinterpret as a chrono date time (with or without time zone)
let dt: PreciseDateTime = dt.to_precise_datetime()?;
// get just the date, for example
let date = dt.to_naive_date();
assert_eq!(date.year(), 2024);