diff options
-rw-r--r-- | CHANGES.md | 6 | ||||
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/lib.rs | 13 | ||||
-rw-r--r-- | tests/tests.rs | 7 |
5 files changed, 32 insertions, 10 deletions
@@ -26,4 +26,8 @@ ## 1.0.7 * 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 +* made the space between time and AM/PM optional +## 1.1.0 +* bumped lazy_static dependency +## 1.2.0 +* added parsable function @@ -25,7 +25,7 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -61,7 +61,7 @@ name = "pidgin" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -95,7 +95,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -110,10 +110,10 @@ dependencies = [ [[package]] name = "two_timer" -version = "1.0.8" +version = "1.2.0" 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)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "pidgin 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -156,7 +156,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" -"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" @@ -1,6 +1,6 @@ [package] name = "two_timer" -version = "1.0.8" +version = "1.2.0" authors = ["dfhoughton <dfhoughton@gmail.com>"] description="parser for English time expressions" homepage="https://github.com/dfhoughton/two-timer" @@ -16,6 +16,6 @@ panic = "abort" [dependencies] pidgin = "0.3" -lazy_static = "1.2" +lazy_static = "1.3.0" chrono = "0.4" regex = "1"
\ No newline at end of file @@ -464,6 +464,19 @@ lazy_static! { pub static ref MATCHER: Matcher = GRAMMAR.matcher().unwrap(); } +/// Simply returns whether the given phrase is parsable as a time expression. +/// +/// # Examples +/// +/// ```rust +/// # extern crate two_timer; +/// # use two_timer::{parsable}; +/// let copacetic = parsable("5/6/69"); +/// ``` +pub fn parsable(phrase: &str) -> bool { + GRAMMAR.rx().unwrap().is_match(phrase) +} + /// Converts a time expression into a pair or timestamps and a boolean indicating whether /// the expression was literally a range, such as "9 to 11", as opposed to "9 AM", say. /// diff --git a/tests/tests.rs b/tests/tests.rs index 902cce3..17acb23 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,6 +1,6 @@ #![feature(test)] extern crate two_timer; -use two_timer::{parse, Config}; +use two_timer::{parse, parsable, Config}; extern crate chrono; use chrono::naive::NaiveDate; use chrono::{Duration, Local}; @@ -11,6 +11,11 @@ fn show_me(p: &str) { } #[test] +fn can_use_parsable() { + assert!(parsable("2019/1/1")); +} + +#[test] fn always() { let alpha = chrono::naive::MIN_DATE.and_hms_milli(0, 0, 0, 0); let omega = chrono::naive::MAX_DATE.and_hms_milli(23, 59, 59, 999); |