Merge pull request #622 from matthiasbeyer/libimagtimeui/remove-unwrap

Libimagtimeui/remove unwrap
This commit is contained in:
Matthias Beyer 2016-08-05 13:19:29 +02:00 committed by GitHub
commit cc7067d106
2 changed files with 33 additions and 20 deletions

View file

@ -58,20 +58,32 @@ impl Parse for Date {
let month = capts.name("M").and_then(|o| FromStr::from_str(o).ok()); let month = capts.name("M").and_then(|o| FromStr::from_str(o).ok());
let day = capts.name("D").and_then(|o| FromStr::from_str(o).ok()); let day = capts.name("D").and_then(|o| FromStr::from_str(o).ok());
if year.is_none() { let year = match year {
None => {
debug!("No year"); debug!("No year");
return None; return None;
} },
if month.is_none() { Some(x) => x,
};
let month = match month {
None => {
debug!("No month"); debug!("No month");
return None; return None;
} },
if day.is_none() { Some(x) => x,
};
let day = match day {
None => {
debug!("No day"); debug!("No day");
return None; return None;
} },
Some(x) => x,
};
Some(Date::new(year.unwrap(), month.unwrap(), day.unwrap()))
Some(Date::new(year, month, day))
}) })
} }

View file

@ -53,16 +53,17 @@ impl Parse for Time {
R.captures(s) R.captures(s)
.and_then(|capts| { .and_then(|capts| {
let hour = capts.name("h").and_then(|o| FromStr::from_str(o).ok());
let minute = capts.name("m").and_then(|o| FromStr::from_str(o).ok()).unwrap_or(0); let minute = capts.name("m").and_then(|o| FromStr::from_str(o).ok()).unwrap_or(0);
let second = capts.name("s").and_then(|o| FromStr::from_str(o).ok()).unwrap_or(0); let second = capts.name("s").and_then(|o| FromStr::from_str(o).ok()).unwrap_or(0);
let hour = match capts.name("h").and_then(|o| FromStr::from_str(o).ok()) {
if hour.is_none() { None => {
debug!("No hour"); debug!("No hour");
return None; return None;
} },
Some(x) => x,
};
Some(Time::new(hour.unwrap(), minute, second)) Some(Time::new(hour, minute, second))
}) })
} }