pub fn parse_datetime(buf: &[u8], dt_utc_offset: FixedOffset) -> Result<DateTime<FixedOffset>> {
    let (date, rest) = parse_date(buf)?;
    if buf.len() <= 8 {
        return Ok(FixedOffset::east(0).from_utc_date(&date).and_hms(0, 0, 0));
    }
    let buf = rest;
    let (time, buf) = parse_time_impl(buf, true)?;
    let len = buf.len();
    let offset = match len {
        0 => {
            // A Date Time value without the optional suffix should be interpreted to be
            // the local time zone of the application creating the Data Element, and can
            // be overridden by the _Timezone Offset from UTC_ attribute.
            let dt: Result<_> = dt_utc_offset
                .from_local_date(&date)
                .and_time(time)
                .single()
                .context(InvalidDateTimeZone);
            return Ok(dt?);
        }
        1 | 2 => return UnexpectedEndOfElement.fail(),
        _ => {
            let tz_sign = buf[0];
            let buf = &buf[1..];
            let (tz_h, tz_m) = match buf.len() {
                1 => (i32::from(buf[0]) - Z, 0),
                2 => return UnexpectedEndOfElement.fail(),
                _ => {
                    let (h_buf, m_buf) = buf.split_at(2);
                    let tz_h = read_number(h_buf)?;
                    let tz_m = read_number(&m_buf[0..usize::min(2, m_buf.len())])?;
                    (tz_h, tz_m)
                }
            };
            let s = (tz_h * 60 + tz_m) * 60;
            match tz_sign {
                b'+' => FixedOffset::east(s),
                b'-' => FixedOffset::west(s),
                c => return InvalidTimeZoneSignToken { value: c }.fail(),
            }
        }
    };

    offset
        .from_utc_date(&date)
        .and_time(time)
        .context(InvalidDateTimeZone)
}
/// Retrieve a DICOM date-time from the given text, while assuming the given
/// UTC offset.
Retrieve a DICOM date-time from the given text, while assuming the given
UTC offset.
Retrieve a DICOM date - time from the given text while assuming the given UTC offset .
pub fn parse_datetime(buf: &[u8], dt_utc_offset: FixedOffset) -> Result<DateTime<FixedOffset>> {
    let (date, rest) = parse_date(buf)?;
    if buf.len() <= 8 {
        return Ok(FixedOffset::east(0).from_utc_date(&date).and_hms(0, 0, 0));
    }
    let buf = rest;
    let (time, buf) = parse_time_impl(buf, true)?;
    let len = buf.len();
    let offset = match len {
        0 => {
            // A Date Time value without the optional suffix should be interpreted to be
            // the local time zone of the application creating the Data Element, and can
            // be overridden by the _Timezone Offset from UTC_ attribute.
            let dt: Result<_> = dt_utc_offset
                .from_local_date(&date)
                .and_time(time)
                .single()
                .context(InvalidDateTimeZone);
            return Ok(dt?);
        }
        1 | 2 => return UnexpectedEndOfElement.fail(),
        _ => {
            let tz_sign = buf[0];
            let buf = &buf[1..];
            let (tz_h, tz_m) = match buf.len() {
                1 => (i32::from(buf[0]) - Z, 0),
                2 => return UnexpectedEndOfElement.fail(),
                _ => {
                    let (h_buf, m_buf) = buf.split_at(2);
                    let tz_h = read_number(h_buf)?;
                    let tz_m = read_number(&m_buf[0..usize::min(2, m_buf.len())])?;
                    (tz_h, tz_m)
                }
            };
            let s = (tz_h * 60 + tz_m) * 60;
            match tz_sign {
                b'+' => FixedOffset::east(s),
                b'-' => FixedOffset::west(s),
                c => return InvalidTimeZoneSignToken { value: c }.fail(),
            }
        }
    };
    offset
        .from_utc_date(&date)
        .and_time(time)
        .context(InvalidDateTimeZone)
}
pub fn parse_datetime ( buf : & [ u8 ] , dt_utc_offset : FixedOffset ) -> Result < DateTime < FixedOffset > > { let ( date , rest ) = parse_date ( buf ) ? ; if buf . len ( ) <= 8 { return Ok ( FixedOffset :: east ( 0 ) . from_utc_date ( & date ) . and_hms ( 0 , 0 , 0 ) ) ; } let buf = rest ; let ( time , buf ) = parse_time_impl ( buf , true ) ? ; let len = buf . len ( ) ; let offset = match len { 0 => { // A Date Time value without the optional suffix should be interpreted to be // the local time zone of the application creating the Data Element, and can // be overridden by the _Timezone Offset from UTC_ attribute. let dt : Result < _ > = dt_utc_offset . from_local_date ( & date ) . and_time ( time ) . single ( ) . context ( InvalidDateTimeZone ) ; return Ok ( dt ? ) ; } 1 | 2 => return UnexpectedEndOfElement . fail ( ) , _ => { let tz_sign = buf [ 0 ] ; let buf = & buf [ 1 .. ] ; let ( tz_h , tz_m ) = match buf . len ( ) { 1 => ( i32 :: from ( buf [ 0 ] ) - Z , 0 ) , 2 => return UnexpectedEndOfElement . fail ( ) , _ => { let ( h_buf , m_buf ) = buf . split_at ( 2 ) ; let tz_h = read_number ( h_buf ) ? ; let tz_m = read_number ( & m_buf [ 0 .. usize :: min ( 2 , m_buf . len ( ) ) ] ) ? ; ( tz_h , tz_m ) } } ; let s = ( tz_h * 60 + tz_m ) * 60 ; match tz_sign { b'+' => FixedOffset :: east ( s ) , b'-' => FixedOffset :: west ( s ) , c => return InvalidTimeZoneSignToken { value : c } . fail ( ) , } } } ; offset . from_utc_date ( & date ) . and_time ( time ) . context ( InvalidDateTimeZone ) }
Retrieve a DICOM date-time from the given text, while assuming the given
UTC offset.
Retrieve a DICOM date - time from the given text while assuming the given UTC offset .
buf
&[u8]
dt_utc_offset
FixedOffset
buf
&[u8]
dt_utc_offset
FixedOffset