diff options
-rw-r--r-- | CHANGES.md | 4 | ||||
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/lib.rs | 8 | ||||
-rw-r--r-- | tests/tests.rs | 16 |
6 files changed, 26 insertions, 7 deletions
@@ -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 @@ -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)", @@ -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" @@ -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 @@ -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 |