pub fn parse_iso_8601_duration(value : &[u8]) -> Result<f64> {
    if value[0] != b'P' {
        let err = ParsingError("Unexpected duration. Should start with \"P\"".to_owned());
        return Err(err);
    }
    let mut base = 1;
    let mut result = 0.;
    if value[1] != b'T' {
        loop {
            let (number, i) = read_next_float(value, base)?;
            if i == value.len() {
                let e = ParsingError("Invalid ISO 8601 duration: end encountered too soon".to_owned());
                return Err(e);
            }
            let factor = match value[i] {
                b'Y' => 365 * 24 * 60 * 60,
                b'M' => 30 * 24 * 60 * 60,
                b'D' => 24 * 60 * 60,
                _ => {
                    let e = ParsingError("Invalid duration: unexpected unit.".to_owned());
                    return Err(e);
                }
            };
            result += number * (factor as f64);
            base = i + 1;
            if base == value.len() {
                return Ok(result as f64);
            }
            if value[base] == b'T' {
                break;
            }
        }
    }
    base += 1;
    loop {
        let (number, i) = read_next_float(value, base)?;
        if i == value.len() {
            let e = ParsingError("Invalid ISO 8601 duration: end encountered too soon".to_owned());
            return Err(e);
        }
        let factor = match value[i] {
            b'H' => 60 * 60,
            b'M' => 60,
            b'S' => 1,
            _ => {
                let e = ParsingError("Invalid duration: unexpected unit.".to_owned());
                return Err(e);
            }
        };
        result += number * (factor as f64);
        base = i + 1;
        if base == value.len() {
            return Ok(result as f64);
        }
    }
}
/// Parse ISO 8601 duration format (e.g. P5Y10M43HT22H8M3S) into the
/// corresponding seconds in a float format.
/// This code could be much simpler if it was RegExp-based but I preferred not
/// to, mainly because I didn't want to incur the size cost of importing regex
/// code in here
Parse ISO 8601 duration format  into the
corresponding seconds in a float format.
This code could be much simpler if it was RegExp-based but I preferred not
to, mainly because I didn't want to incur the size cost of importing regex
code in here
Parse ISO 8601 duration format into the corresponding seconds in a float format . This code could be much simpler if it was RegExp - based but I preferred not to mainly because I didn ' t want to incur the size cost of importing regex code in here
pub fn parse_iso_8601_duration(value : &[u8]) -> Result<f64> {
    if value[0] != b'P' {
        let err = ParsingError("Unexpected duration. Should start with \"P\"".to_owned());
        return Err(err);
    }
    let mut base = 1;
    let mut result = 0.;
    if value[1] != b'T' {
        loop {
            let (number, i) = read_next_float(value, base)?;
            if i == value.len() {
                let e = ParsingError("Invalid ISO 8601 duration: end encountered too soon".to_owned());
                return Err(e);
            }
            let factor = match value[i] {
                b'Y' => 365 * 24 * 60 * 60,
                b'M' => 30 * 24 * 60 * 60,
                b'D' => 24 * 60 * 60,
                _ => {
                    let e = ParsingError("Invalid duration: unexpected unit.".to_owned());
                    return Err(e);
                }
            };
            result += number * (factor as f64);
            base = i + 1;
            if base == value.len() {
                return Ok(result as f64);
            }
            if value[base] == b'T' {
                break;
            }
        }
    }
    base += 1;
    loop {
        let (number, i) = read_next_float(value, base)?;
        if i == value.len() {
            let e = ParsingError("Invalid ISO 8601 duration: end encountered too soon".to_owned());
            return Err(e);
        }
        let factor = match value[i] {
            b'H' => 60 * 60,
            b'M' => 60,
            b'S' => 1,
            _ => {
                let e = ParsingError("Invalid duration: unexpected unit.".to_owned());
                return Err(e);
            }
        };
        result += number * (factor as f64);
        base = i + 1;
        if base == value.len() {
            return Ok(result as f64);
        }
    }
}
pub fn parse_iso_8601_duration ( value : & [ u8 ] ) -> Result < f64 > { if value [ 0 ] != b'P' { let err = ParsingError ( " \" \" " . to_owned ( ) ) ; return Err ( err ) ; } let mut base = 1 ; let mut result = 0. ; if value [ 1 ] != b'T' { loop { let ( number , i ) = read_next_float ( value , base ) ? ; if i == value . len ( ) { let e = ParsingError ( " " . to_owned ( ) ) ; return Err ( e ) ; } let factor = match value [ i ] { b'Y' => 365 * 24 * 60 * 60 , b'M' => 30 * 24 * 60 * 60 , b'D' => 24 * 60 * 60 , _ => { let e = ParsingError ( " " . to_owned ( ) ) ; return Err ( e ) ; } } ; result += number * ( factor as f64 ) ; base = i + 1 ; if base == value . len ( ) { return Ok ( result as f64 ) ; } if value [ base ] == b'T' { break ; } } } base += 1 ; loop { let ( number , i ) = read_next_float ( value , base ) ? ; if i == value . len ( ) { let e = ParsingError ( " " . to_owned ( ) ) ; return Err ( e ) ; } let factor = match value [ i ] { b'H' => 60 * 60 , b'M' => 60 , b'S' => 1 , _ => { let e = ParsingError ( " " . to_owned ( ) ) ; return Err ( e ) ; } } ; result += number * ( factor as f64 ) ; base = i + 1 ; if base == value . len ( ) { return Ok ( result as f64 ) ; } } }
Parse ISO 8601 duration format (e.g.
Parse ISO 8601 duration format ( e . g .
value
&[u8]
value
&[u8]