date_time_parser/
lib.rs

1//! # Date Time Parser: Rust NLP Library
2//!
3//! It aims to parse unstructered text into [`NaiveDate`](https://docs.rs/chrono/0.4.0/chrono/naive/struct.NaiveDate.html) and [`NaiveTime`](https://docs.rs/chrono/0.4.0/chrono/naive/struct.NaiveTime.html) formats.
4//! * Date Time Parser has the ability to be timezone aware, but defaults to UTC.
5//! * Allows for parse to be relative to current date/time, or relative to a custom date/time.
6//! * Leverages [chrono](https://docs.rs/chrono/0.4.11/chrono/) and [regex](https://docs.rs/regex/1.3.6/regex/) crates.
7//!
8//! ## Usage
9//! Put this in your `Cargo.toml`:
10//! ```toml,ignore
11//! [dependencies]
12//! date_time_parser = "0.1.0"
13//! ```
14//! Then put this in your crate root:
15//! ```
16//! extern crate date_time_parser;
17//! ```
18//!
19//! ## Example: Find a Date
20//! General use of this package involves passing English natural language that includes a date
21//! to the [`DateParser`](../date_time_parser/date_parse/struct.DateParser.html) struct to parse the expression. If a date is found, it will parse the expression into the
22//! [`NaiveDate`](https://docs.rs/chrono/0.4.0/chrono/naive/struct.NaiveDate.html) format.
23//! ```
24//! use date_time_parser::DateParser;
25//! use chrono::{prelude::*, Duration, Local, NaiveDate, NaiveDateTime, Weekday};
26//!
27//! let date = DateParser::parse("Lunch on June 5th");
28//! let year = Local::now().year();
29//! assert_eq!(date, Some(NaiveDate::from_ymd(year, 6, 5)));
30//! ```
31//!
32//! ## Example: Find a Time
33//! Similarly to parsing dates, this package can also be used to parse time expressions. Pass
34//! English natural language that includes a time (relative or absolute) to the [`TimeParser`](../date_time_parser/time_parse/struct.TimeParser.html) struct
35//! to parse the text. A successful parse results in a [`NaiveTime`](https://docs.rs/chrono/0.4.0/chrono/naive/struct.NaiveTime.html) from the natural language expression.
36//! ```
37//! use date_time_parser::TimeParser;
38//! use chrono::NaiveTime;
39//!
40//! let time = TimeParser::parse("6:30pm dinner");
41//! assert_eq!(time, Some(NaiveTime::from_hms(18, 30, 0)));
42//! ```
43//!
44//! ## Example: Not a Date/Time
45//! If the package gets an expression that for it cannot find a valid date or time, the [`TimeParser::parse`](../date_time_parser/time_parse/struct.TimeParser.html#method.parse) function
46//! will return `None` for that string.
47//! ```
48//! use date_time_parser::TimeParser;
49//! use chrono::NaiveTime;
50//!
51//! let time = TimeParser::parse("foo bar");
52//! assert_eq!(time, None);
53//! ```
54
55mod date_parse;
56mod recognizable;
57mod time_parse;
58pub use date_parse::DateParser;
59pub use recognizable::Recognizable;
60pub use time_parse::TimeParser;