summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2019-06-30 13:23:41 -0400
committerdfhoughton <dfhoughton@gmail.com>2019-06-30 13:23:41 -0400
commitf9ce85e4497669ceb235865dfe6daff9e3cf5729 (patch)
treec0257127018d84f5147c4939258b534f42495373
parente3df19074be7c5f4a175b415291434048eb811e1 (diff)
downloadtwo-timer-f9ce85e4497669ceb235865dfe6daff9e3cf5729.zip
added parsable function
-rw-r--r--CHANGES.md6
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml4
-rw-r--r--src/lib.rs13
-rw-r--r--tests/tests.rs7
5 files changed, 32 insertions, 10 deletions
diff --git a/CHANGES.md b/CHANGES.md
index a8b5eb6..1271e20 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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
diff --git a/Cargo.lock b/Cargo.lock
index 6f47ca6..3f447c5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index df580bd..a4ae8c4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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
diff --git a/src/lib.rs b/src/lib.rs
index 354578b..fd1d4a7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);