Crate langtime

Source
Expand description

Easy to use crate for converting english-spelled dates to chrono DateTimes.

This crate does a similar job to what chrono_english already does, but using nom parsers. This has two advantages:

  • new formats are easier to add
  • combinations of date and time formats are declarative

Right now, this crate only exposes one function: parse. This function should never panic, but since this library is still under development, if you find anything wrong or if it ever panics, please write an issue on the github repo.

§Example

match langtime::parse("yesterday at 9pm") {
    Ok(datetime) => println!("{:?}", datetime),
    Err(_) => println!("Cannot parse input as a date")
}

Structs§

ParseConfig
The configuration for the langtime parse function

Enums§

Dialect
A list of english dialects that will influence how the parser will convert the input string. For example, using mm-dd-yyyy instead of dd-mm-yyyy.

Functions§

parse
This function will take a string as an input and try to parse it into a valid Datetime with the local timezone.
parse_with_config
This function takes an input string and tries to parse it into a valid Datetime with the local timezone. It also takes a configuration to set the desired english dialect, or to decide whether the string has to be matched in full, or just partially.