8 releases

0.2.2 Dec 27, 2023
0.2.1 Jan 22, 2023
0.2.0 Dec 14, 2022
0.1.5 Feb 18, 2022

#137 in Date and time

Download history 87/week @ 2024-07-24 64/week @ 2024-07-31 64/week @ 2024-08-07 48/week @ 2024-08-14 54/week @ 2024-08-21 56/week @ 2024-08-28 81/week @ 2024-09-04 121/week @ 2024-09-11 357/week @ 2024-09-18 1605/week @ 2024-09-25 255/week @ 2024-10-02 104/week @ 2024-10-09 211/week @ 2024-10-16 208/week @ 2024-10-23 177/week @ 2024-10-30 210/week @ 2024-11-06

815 downloads per month
Used in 2 crates

MIT license

58KB
1.5K SLoC

FuzzyDate: Date Input for Humans

FuzzyDate Github Actions FuzzyDate on crates.io FuzzyDate on docs.rs

A flexible date parser library for Rust.

Usage

Put this in your Cargo.toml:

[dependencies]
fuzzydate = "0.2"

Example

use fuzzydate::parse;

fn main() {
    let input = "five days after this friday";
    let date = parse(input).unwrap();
    println!("{:?}", date);
}

lib.rs:

FuzzyDate: Date Input for Humans

A Parser which can turn a variety of input strings into a DateTime

Usage

Put this in your Cargo.toml:

fuzzydate = "0.2"

Example

use fuzzydate::parse;
use chrono::NaiveDateTime;

fn main() {
    let date_string = "Five days after 2/12/22 5:00 PM";
    let date = parse(date_string).unwrap();
    println!("{:?}", date);
}

Any relevant date time information not specified is assumed to be the value of the current date time.

Grammar

<datetime> ::= <time>
             | <date> <time>
             | <date> , <time>
             | <duration> after <datetime>
             | <duration> from <datetime>
             | <duration> before <datetime>
             | <duration> ago
             | now

<article> ::= a
           | an
           | the

<date> ::= today
         | tomorrow
         | yesterday
         | <num> / <num> / <num>
         | <num> - <num> - <num>
         | <num> . <num> . <num>
         | <month> <num> <num>
         | <relative_specifier> <unit>
         | <relative_specifier> <weekday>
         | <weekday>

<relative_specifier> ::= this
                       | next
                       | last

<weekday> ::= monday
            | tuesday
            | wednesday
            | thursday
            | friday
            | saturday
            | sunday
            | mon
            | tue
            | wed
            | thu
            | fri
            | sat
            | sun

<month> ::= january
          | february
          | march
          | april
          | may
          | june
          | july
          | august
          | september
          | october
          | november
          | december
          | jan
          | feb
          | mar
          | apr
          | jun
          | jul
          | aug
          | sep
          | oct
          | nov
          | dec

<duration> ::= <num> <unit>
             | <article> <unit>
             | <duration> and <duration>

<time> ::= <num>:<num>
         | <num>:<num> am
         | <num>:<num> pm
         |

<unit> ::= day
         | days
         | week
         | weeks
         | hour
         | hours
         | minute
         | minutes
         | min
         | mins
         | month
         | months
         | year
         | years

<num> ::= <num_triple> <num_triple_unit> and <num>
        | <num_triple> <num_triple_unit> <num>
        | <num_triple> <num_triple_unit>
        | <num_triple_unit> and <num>
        | <num_triple_unit> <num>
        | <num_triple_unit>
        | <num_triple>
        | NUM   ; number literal greater than or equal to 1000

<num_triple> ::= <ones> hundred and <num_double>
               | <ones> hundred <num_double>
               | <ones> hundred
               | hundred and <num_double>
               | hundred <num_double>
               | hundred
               | <num_double>
               | NUM    ; number literal less than 1000 and greater than 99

<num_triple_unit> ::= thousand
                    | million
                    | billion

<num_double> ::= <ones>
               | <tens> - <ones>
               | <tens> <ones>
               | <tens>
               | <teens>
               | NUM    ; number literal less than 100 and greater than 19

<tens> ::= twenty
         | thirty
         | forty
         | fifty
         | sixty
         | seventy
         | eighty
         | ninety

<teens> ::= ten
          | eleven
          | twelve
          | thirteen
          | fourteen
          | fifteen
          | sixteen
          | seventeen
          | eighteen
          | nineteen
          | NUM     ; number literal less than 20 and greater than 9

<ones> ::= one
         | two
         | three
         | four
         | five
         | six
         | seven
         | eight
         | nine
         | NUM      ; number literal less than 10

Dependencies

~1.2–1.9MB
~33K SLoC