use std::time::Duration;
pub fn get_boolean_value(value: &str) -> Option<bool> {
match value {
"false" | "FALSE" => Some(false),
"true" | "TRUE" => Some(true),
_ => None
}
}
pub fn get_time_value(value: &str) -> Option<Duration> {
let mut time_string = String::new();
let mut unit_string = String::new();
for ch in value.chars() {
if ch.is_digit(10) && unit_string.is_empty() {
time_string.push(ch);
} else if ch.is_digit(10) == false && time_string.is_empty() == false {
unit_string.push(ch);
} else {
return None;
}
}
if time_string.is_empty() {
return None;
}
if let Ok(time) = time_string.parse::<u64>() {
match unit_string.trim() {
"us" | "µs" => Some(Duration::from_micros(time)),
"ms" => Some(Duration::from_millis(time)),
"s" | "" => Some(Duration::from_secs(time)),
_ => None
}
} else {
None
}
}