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 |
#112 in Date and time
2,452 downloads per month
Used in 2 crates
58KB
1.5K
SLoC
FuzzyDate: Date Input for Humans
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–2MB
~35K SLoC