summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2019-01-12 17:18:37 -0500
committerdfhoughton <dfhoughton@gmail.com>2019-01-12 17:18:37 -0500
commitd3fa93c177c650edd01c0e729f2f9da86c355ee5 (patch)
tree7431bcfbe07d80b70ba87e2b44aae7748bdc436e
parenta5c0ff8e41b31d0c71001a339b6099fcbc40363d (diff)
downloadtwo-timer-d3fa93c177c650edd01c0e729f2f9da86c355ee5.zip
added msg method to TimeError
-rw-r--r--CHANGES.md2
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs15
4 files changed, 18 insertions, 3 deletions
diff --git a/CHANGES.md b/CHANGES.md
index fedcf4d..ae699d6 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,3 +6,5 @@
* don't require space between era suffix and year -- "100AD" is as good as "100 AD"
## 1.0.1
* removing some documentation
+## 1.0.2
+* added `msg` method to `TimeError` \ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 1d145a8..9dadea0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -108,7 +108,7 @@ dependencies = [
[[package]]
name = "two_timer"
-version = "1.0.1"
+version = "1.0.2"
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 baf6f4d..55f896a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "two_timer"
-version = "1.0.1"
+version = "1.0.2"
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 cdd6e8a..3b345e7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -185,7 +185,7 @@ use pidgin::{Grammar, Match, Matcher};
use regex::Regex;
lazy_static! {
- // making this public is useful for testing, but best to keep it hidden to
+ // making this public is useful for testing, but best to keep it hidden to
// limit complexity and commitment
#[doc(hidden)]
pub static ref GRAMMAR: Grammar = grammar!{
@@ -402,6 +402,19 @@ pub enum TimeError {
NoPayPeriod(String),
}
+impl TimeError {
+ /// Extracts error message.
+ pub fn msg(&self) -> &str {
+ match self {
+ TimeError::Parse(s) => s.as_ref(),
+ TimeError::Misordered(s) => s.as_ref(),
+ TimeError::ImpossibleDate(s) => s.as_ref(),
+ TimeError::Weekday(s) => s.as_ref(),
+ TimeError::NoPayPeriod(s) => s.as_ref(),
+ }
+ }
+}
+
/// 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.
///