diff options
-rw-r--r-- | CHANGES.md | 2 | ||||
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 7 | ||||
-rw-r--r-- | tests/tests.rs | 6 |
5 files changed, 16 insertions, 3 deletions
@@ -1,5 +1,7 @@ # Change Log +## 1.3.4 +* fixed panic when parsing "24" ## 1.3.3 * revert `ToString` to `&str` for greater efficiency ## 1.3.2 @@ -171,7 +171,7 @@ dependencies = [ [[package]] name = "two_timer" -version = "1.3.3" +version = "1.3.4" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1,6 +1,6 @@ [package] name = "two_timer" -version = "1.3.3" +version = "1.3.4" authors = ["dfhoughton <dfhoughton@gmail.com>"] description="parser for English time expressions" homepage="https://github.com/dfhoughton/two-timer" @@ -1470,7 +1470,12 @@ fn time(m: &Match) -> (u32, Option<u32>, Option<u32>, bool) { }; } let hour = if let Some(hour_24) = m.name("hour_24") { - s_to_n(hour_24.name("h24").unwrap().as_str()) + let hour = s_to_n(hour_24.name("h24").unwrap().as_str()); + if hour == 24 { + 0 + } else { + hour + } } else if let Some(hour_12) = m.name("hour_12") { let mut hour = s_to_n(hour_12.name("h12").unwrap().as_str()); hour = if let Some(am_pm) = m.name("am_pm") { diff --git a/tests/tests.rs b/tests/tests.rs index ecf7ccb..a814899 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1535,3 +1535,9 @@ fn no_space_before_pm() { } } } + +#[test] +fn relative_time_regression() { + parse("24", None).unwrap(); + assert!(true, "'24' didn't cause a panic"); +}
\ No newline at end of file |