///|
/// Parse one Retry-After field value into milliseconds. Only SP/HTAB are
/// trimmed. Strict IMF-fixdate or ASCII delta-seconds; no comma lists.
/// now_seconds must be a Unix wall-clock timestamp in years 1601..9999.
/// Dates in the past produce zero; overflow and malformed input produce None.
pub fn retry_after_delay(value : String, now_seconds : Int64) -> Int64? {
  if value.length() > 1024 ||
    now_seconds < -11644473600L ||
    now_seconds > 253402300799L {
    return None
  }
  let chars = value.to_array()
  let mut first = 0
  let mut last = chars.length()
  while first < last && (chars[first] == ' ' || chars[first] == '\t') {
    first = first + 1
  }
  while last > first && (chars[last - 1] == ' ' || chars[last - 1] == '\t') {
    last = last - 1
  }
  if first == last {
    return None
  }
  match parse_digit(chars[first]) {
    Some(_) => {
      let mut seconds = 0L
      for i = first; i < last; i = i + 1 {
        let digit = match parse_digit(chars[i]) {
          Some(d) => d.to_int64()
          None => return None
        }
        // Largest whole seconds whose millisecond value fits in Int64.
        if seconds > (9223372036854775L - digit) / 10L {
          return None
        }
        seconds = seconds * 10L + digit
      }
      Some(seconds * 1000L)
    }
    None => {
      let text = String::from_array(chars[first:last].to_owned())
      match parse_http_date(text) {
        None => None
        Some(date) =>
          Some(
            if date <= now_seconds {
              0L
            } else {
              (date - now_seconds) * 1000L
            },
          )
      }
    }
  }
}