summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md2
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs7
-rw-r--r--tests/tests.rs6
5 files changed, 16 insertions, 3 deletions
diff --git a/CHANGES.md b/CHANGES.md
index bed6f8d..dc0f297 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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
diff --git a/Cargo.lock b/Cargo.lock
index fbb27fe..e45eee4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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)",
diff --git a/Cargo.toml b/Cargo.toml
index 64014c9..5691088 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/src/lib.rs b/src/lib.rs
index c544620..bc54e38 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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