summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2019-02-16 11:01:17 -0500
committerdfhoughton <dfhoughton@gmail.com>2019-02-16 11:01:17 -0500
commit06c54e9a128441a078b41a6d66076c8db63be0e0 (patch)
treea95d924a594f997a422dca6ed03c8ce013a2c01c
parent72efcceb945fb80a576775a513b64e104078e9f0 (diff)
downloadtwo-timer-06c54e9a128441a078b41a6d66076c8db63be0e0.zip
remove need for space between hour and AM/PM
-rw-r--r--CHANGES.md4
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--README.md1
-rw-r--r--src/lib.rs8
-rw-r--r--tests/tests.rs16
6 files changed, 26 insertions, 7 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 8ac3e0a..a8b5eb6 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -24,4 +24,6 @@
* added "before and after"
* fixed "Friday the 13th" and "the 31st" to scan back through the calendar to the nearest match
## 1.0.7
-* added `<specific_time>` pattern: e.g., 1969-05-06 12:03:05 \ No newline at end of file
+* added `<specific_time>` pattern: e.g., 1969-05-06 12:03:05
+## 1.0.8
+* made the space between time and AM/PM optional \ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 62c7e5e..6f47ca6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -110,7 +110,7 @@ dependencies = [
[[package]]
name = "two_timer"
-version = "1.0.7"
+version = "1.0.8"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 7ea2a3e..df580bd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "two_timer"
-version = "1.0.7"
+version = "1.0.8"
authors = ["dfhoughton <dfhoughton@gmail.com>"]
description="parser for English time expressions"
homepage="https://github.com/dfhoughton/two-timer"
diff --git a/README.md b/README.md
index 96ce49d..bc93695 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@ Some expressions it can handle:
* June 6, 2010
* forever
* 3:00 AM
+* 3AM
* June '05
* Monday through next Thursday
* from mon at 15:00:05 to now
diff --git a/src/lib.rs b/src/lib.rs
index 15a11e8..354578b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -301,15 +301,15 @@ lazy_static! {
// various phrases all meaning from the first measurable moment to the last
a_count => [["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]]
adverb => [["now", "today", "tomorrow", "yesterday"]]
- am_pm => (?-i) [["am", "AM", "pm", "PM", "a.m.", "A.M.", "p.m.", "P.M."]]
+ am_pm => (?-ib) [["am", "AM", "pm", "PM", "a.m.", "A.M.", "p.m.", "P.M."]]
bce => (?-ib) [["bce", "b.c.e.", "bc", "b.c.", "BCE", "B.C.E.", "BC", "B.C."]]
ce => (?-ib) [["ce", "c.e.", "ad", "a.d.", "CE", "C.E.", "AD", "A.D."]]
direction -> [["before", "after", "around", "before and after"]]
displacement => [["week", "day", "hour", "minute", "second"]] ("s")? // not handling variable-width periods like months or years
from_now_or_ago => [["from now", "ago"]]
- h12 => [(1..=12).into_iter().collect::<Vec<_>>()]
+ h12 => (?-B) [(1..=12).into_iter().collect::<Vec<_>>()]
h24 => [(1..=24).into_iter().collect::<Vec<_>>()]
- minute => [ (0..60).into_iter().map(|i| format!("{:02}", i)).collect::<Vec<_>>() ]
+ minute => (?-B) [ (0..60).into_iter().map(|i| format!("{:02}", i)).collect::<Vec<_>>() ]
modifier => [["this", "last", "next"]]
named_time => [["noon", "midnight"]]
n_year => r(r"\b(?:[1-9][0-9]{0,4}|0)\b")
@@ -317,7 +317,7 @@ lazy_static! {
unit => [["week", "day", "hour", "minute", "second"]] ("s")?
universal => [["always", "ever", "all time", "forever", "from beginning to end", "from the beginning to the end"]]
up_to => [["to", "until", "up to", "till"]]
- second => [ (0..60).into_iter().map(|i| format!("{:02}", i)).collect::<Vec<_>>() ]
+ second => (?-B) [ (0..60).into_iter().map(|i| format!("{:02}", i)).collect::<Vec<_>>() ]
suffix_year => r(r"\b[1-9][0-9]{0,4}")
through => [["up through", "through", "thru"]] | r("-+")
diff --git a/tests/tests.rs b/tests/tests.rs
index 7ee0325..9f7f1ca 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1463,4 +1463,20 @@ fn specific_time() {
assert!(false, "didn't match");
}
}
+}
+
+#[test]
+fn no_space_before_pm() {
+ let d1 = NaiveDate::from_ymd(1969, 5, 6).and_hms(13, 0, 0);
+ let d2 = d1 + Duration::hours(1);
+ match parse("1969-05-06 at 1PM", None) {
+ Ok((start, end, _)) => {
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+ }
+ Err(e) => {
+ println!("{:?}", e);
+ assert!(false, "didn't match");
+ }
+ }
} \ No newline at end of file