Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp DICOM datetime #453

Merged
merged 23 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod serialize;
pub use self::deserialize::Error as DeserializeError;
pub use self::partial::{DicomDate, DicomDateTime, DicomTime};
pub use self::person_name::PersonName;
pub use self::range::{AsRange, DateRange, DateTimeRange, TimeRange, PreciseDateTimeResult};
pub use self::range::{AsRange, DateRange, DateTimeRange, TimeRange, PreciseDateTime};

pub use self::primitive::{
CastValueError, ConvertValueError, InvalidValueReadError, ModifyValueError, PrimitiveValue,
Expand Down Expand Up @@ -661,7 +661,7 @@ where
}
}

/// Retrieves the primitive value as a [`PersonName`][1].
/// Retrieves the primitive value as a [`PersonName`].
///
/// [1]: super::value::person_name::PersonName
Enet4 marked this conversation as resolved.
Show resolved Hide resolved
pub fn to_person_name(&self) -> Result<PersonName<'_>, ConvertValueError> {
Expand Down
20 changes: 10 additions & 10 deletions core/src/value/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ enum DicomTimeImpl {
/// `DicomDateTime` is always internally represented by a [DicomDate].
/// The [DicomTime] and a timezone [FixedOffset] values are optional.
///
/// It implements [AsRange] trait, which serves to retrieve a [PreciseDateTimeResult] from values
/// It implements [AsRange] trait, which serves to retrieve a [PreciseDateTime](crate::value::range::PreciseDateTime) from values
/// with missing components.
/// # Example
/// ```
/// # use std::error::Error;
/// # use std::convert::TryFrom;
/// use chrono::{DateTime, FixedOffset, TimeZone, NaiveDateTime, NaiveDate, NaiveTime};
/// use dicom_core::value::{DicomDate, DicomTime, DicomDateTime, AsRange, PreciseDateTimeResult};
/// use dicom_core::value::{DicomDate, DicomTime, DicomDateTime, AsRange, PreciseDateTime};
/// # fn main() -> Result<(), Box<dyn Error>> {
///
/// let offset = FixedOffset::east_opt(3600).unwrap();
Expand All @@ -206,18 +206,18 @@ enum DicomTimeImpl {
/// DicomDate::from_y(2020)?,
/// offset
/// );
/// // the earliest possible value is output as a [PreciseDateTimeResult]
/// // the earliest possible value is output as a [PreciseDateTime]
/// assert_eq!(
/// dt.earliest()?,
/// PreciseDateTimeResult::TimeZone(
/// PreciseDateTime::TimeZone(
/// offset.from_local_datetime(&NaiveDateTime::new(
/// NaiveDate::from_ymd_opt(2020, 1, 1).unwrap(),
/// NaiveTime::from_hms_opt(0, 0, 0).unwrap()
/// )).single().unwrap())
/// );
/// assert_eq!(
/// dt.latest()?,
/// PreciseDateTimeResult::TimeZone(
/// PreciseDateTime::TimeZone(
/// offset.from_local_datetime(&NaiveDateTime::new(
/// NaiveDate::from_ymd_opt(2020, 12, 31).unwrap(),
/// NaiveTime::from_hms_micro_opt(23, 59, 59, 999_999).unwrap()
Expand Down Expand Up @@ -879,7 +879,7 @@ impl DicomDateTime {

#[cfg(test)]
mod tests {
use crate::value::range::{AsRange, PreciseDateTimeResult};
use crate::value::range::{AsRange, PreciseDateTime};

use super::*;
use chrono::{NaiveDateTime, TimeZone};
Expand Down Expand Up @@ -1140,7 +1140,7 @@ mod tests {
DicomDateTime::from_date(DicomDate::from_ym(2020, 2).unwrap())
.earliest()
.unwrap(),
PreciseDateTimeResult::Naive(NaiveDateTime::new(
PreciseDateTime::Naive(NaiveDateTime::new(
NaiveDate::from_ymd_opt(2020, 2, 1).unwrap(),
NaiveTime::from_hms_micro_opt(0, 0, 0, 0).unwrap()
))
Expand All @@ -1153,7 +1153,7 @@ mod tests {
)
.latest()
.unwrap(),
PreciseDateTimeResult::TimeZone(
PreciseDateTime::TimeZone(
FixedOffset::east_opt(0)
.unwrap()
.from_local_datetime(&NaiveDateTime::new(
Expand All @@ -1173,7 +1173,7 @@ mod tests {
.unwrap()
.earliest()
.unwrap(),
PreciseDateTimeResult::TimeZone(
PreciseDateTime::TimeZone(
FixedOffset::east_opt(0)
.unwrap()
.from_local_datetime(&NaiveDateTime::new(
Expand All @@ -1192,7 +1192,7 @@ mod tests {
.unwrap()
.latest()
.unwrap(),
PreciseDateTimeResult::TimeZone(
PreciseDateTime::TimeZone(
FixedOffset::east_opt(0)
.unwrap()
.from_local_datetime(&NaiveDateTime::new(
Expand Down
14 changes: 7 additions & 7 deletions core/src/value/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ impl PrimitiveValue {
/// # use smallvec::smallvec;
/// # use chrono::{DateTime, FixedOffset, TimeZone, NaiveDateTime, NaiveDate, NaiveTime};
/// # use std::error::Error;
/// use dicom_core::value::{DicomDateTime, AsRange, DateTimeRange, PreciseDateTimeResult};
/// use dicom_core::value::{DicomDateTime, AsRange, DateTimeRange, PreciseDateTime};
///
/// # fn main() -> Result<(), Box<dyn Error>> {
///
Expand All @@ -2676,14 +2676,14 @@ impl PrimitiveValue {
///
/// assert_eq!(
/// dt_value.earliest()?,
/// PreciseDateTimeResult::Naive(NaiveDateTime::new(
/// PreciseDateTime::Naive(NaiveDateTime::new(
/// NaiveDate::from_ymd_opt(2012, 12, 21).unwrap(),
/// NaiveTime::from_hms_micro_opt(9, 30, 1, 100_000).unwrap()
/// ))
/// );
/// assert_eq!(
/// dt_value.latest()?,
/// PreciseDateTimeResult::Naive(NaiveDateTime::new(
/// PreciseDateTime::Naive(NaiveDateTime::new(
/// NaiveDate::from_ymd_opt(2012, 12, 21).unwrap(),
/// NaiveTime::from_hms_micro_opt(9, 30, 1, 199_999).unwrap()
/// ))
Expand All @@ -2698,7 +2698,7 @@ impl PrimitiveValue {
///
/// assert_eq!(
/// dt_value.exact()?,
/// PreciseDateTimeResult::TimeZone(
/// PreciseDateTime::TimeZone(
/// default_offset
/// .ymd_opt(2012, 12, 21).unwrap()
/// .and_hms_micro_opt(9, 30, 1, 123_456).unwrap()
Expand Down Expand Up @@ -2980,7 +2980,7 @@ impl PrimitiveValue {
/// # use dicom_core::value::{C, PrimitiveValue};
/// use chrono::{DateTime, NaiveDate, NaiveTime, NaiveDateTime, FixedOffset, TimeZone, Local};
/// # use std::error::Error;
/// use dicom_core::value::{DateTimeRange, PreciseDateTimeResult};
/// use dicom_core::value::{DateTimeRange, PreciseDateTime};
///
/// # fn main() -> Result<(), Box<dyn Error>> {
///
Expand All @@ -2992,7 +2992,7 @@ impl PrimitiveValue {
/// // lower bound of range is parsed into a PreciseDateTimeResult::TimeZone variant
/// assert_eq!(
/// dt_range.start(),
/// Some(PreciseDateTimeResult::TimeZone(
/// Some(PreciseDateTime::TimeZone(
/// FixedOffset::east_opt(5*3600).unwrap().ymd_opt(1992, 1, 1).unwrap()
/// .and_hms_micro_opt(15, 30, 20, 123_000).unwrap()
/// )
Expand All @@ -3002,7 +3002,7 @@ impl PrimitiveValue {
/// // upper bound of range is parsed into a PreciseDateTimeResult::TimeZone variant
/// assert_eq!(
/// dt_range.end(),
/// Some(PreciseDateTimeResult::TimeZone(
/// Some(PreciseDateTime::TimeZone(
/// FixedOffset::east_opt(3*3600).unwrap().ymd_opt(1993, 12, 31).unwrap()
/// .and_hms_micro_opt(23, 59, 59, 999_999).unwrap()
/// )
Expand Down
Loading
Loading