├── .gitignore ├── examples └── stdin.rs ├── Cargo.toml ├── .github └── workflows │ └── tests.yml ├── README.md ├── LICENSE └── src ├── lib.rs ├── lexer.rs └── ast.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock 3 | -------------------------------------------------------------------------------- /examples/stdin.rs: -------------------------------------------------------------------------------- 1 | extern crate fuzzydate; 2 | use fuzzydate::parse; 3 | use std::io::stdin; 4 | 5 | fn main() { 6 | let mut buf = String::new(); 7 | while stdin().read_line(&mut buf).is_ok() { 8 | let date = parse(&buf); 9 | println!("{:?}", date); 10 | buf.clear(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuzzydate" 3 | description = "A flexible date parsing library" 4 | version = "0.2.1" 5 | edition = "2021" 6 | authors = ["Devin Vander Stelt"] 7 | keywords = ["date", "time", "parse", "fuzzy", "string"] 8 | categories = [ 9 | "accessibility", 10 | "date-and-time", 11 | "parser-implementations", 12 | "text-processing", 13 | ] 14 | license = "MIT" 15 | repository = "https://github.com/DevinVS/fuzzydate" 16 | 17 | [dependencies] 18 | chrono = "0.4" 19 | lazy_static = "1.4" 20 | thiserror = "1.0" 21 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | check: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - uses: actions-rs/toolchain@v1 20 | with: 21 | profile: minimal 22 | toolchain: stable 23 | override: true 24 | - uses: actions-rs/cargo@v1 25 | with: 26 | command: check 27 | - uses: actions-rs/tarpaulin@v0.1 28 | with: 29 | version: '0.15.0' 30 | args: '-- --test-threads 1' 31 | - name: Archive code coverage results 32 | uses: actions/upload-artifact@v1 33 | with: 34 | name: code-coverage-report 35 | path: cobertura.xml 36 | - name: Code Coverage Summary Report 37 | uses: irongut/CodeCoverageSummary@v1.2.0 38 | with: 39 | filename: cobertura.xml 40 | badge: true 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [FuzzyDate][docsrs]: Date Input for Humans 2 | 3 | 4 | [![FuzzyDate Github Actions][gh-image]][gh-checks] 5 | [![FuzzyDate on crates.io][cratesio-image]][cratesio] 6 | [![FuzzyDate on docs.rs][docsrs-image]][docsrs] 7 | 8 | [gh-image]: https://github.com/DevinVS/fuzzydate/actions/workflows/tests.yml/badge.svg 9 | [gh-checks]: https://github.com/DevinVS/fuzzydate/actions/workflows/tests.yml 10 | [cratesio-image]: https://img.shields.io/crates/v/fuzzydate.svg 11 | [cratesio]: https://crates.io/crates/fuzzydate 12 | [docsrs-image]: https://docs.rs/fuzzydate/badge.svg 13 | [docsrs]: https://docs.rs/fuzzydate 14 | 15 | A flexible date parser library for Rust. 16 | 17 | ## Usage 18 | 19 | Put this in your `Cargo.toml`: 20 | 21 | ```toml 22 | [dependencies] 23 | fuzzydate = "0.2" 24 | ``` 25 | 26 | ## Example 27 | 28 | ```rust 29 | use fuzzydate::parse; 30 | 31 | fn main() { 32 | let input = "five days after this friday"; 33 | let date = parse(input).unwrap(); 34 | println!("{:?}", date); 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Devin Vander Stelt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::needless_doctest_main)] 2 | //! # FuzzyDate: Date Input for Humans 3 | //! 4 | //! A Parser which can turn a variety of input strings into a DateTime 5 | //! 6 | //! ## Usage 7 | //! 8 | //! Put this in your `Cargo.toml`: 9 | //! 10 | //! ```toml 11 | //! fuzzydate = "0.2" 12 | //! ``` 13 | //! 14 | //! ## Example 15 | //! 16 | //! ```rust 17 | //! use fuzzydate::parse; 18 | //! use chrono::NaiveDateTime; 19 | //! 20 | //! fn main() { 21 | //! let date_string = "Five days after 2/12/22 5:00 PM"; 22 | //! let date = parse(date_string).unwrap(); 23 | //! println!("{:?}", date); 24 | //! } 25 | //! ``` 26 | //! 27 | //! Any relevant date time information not specified is assumed to be 28 | //! the value of the current date time. 29 | //! 30 | //! ## Grammar 31 | //! ```text 32 | //! ::=