15 releases (stable)

Uses old Rust 2015

2.0.1 Aug 18, 2024
2.0.0 Aug 24, 2023
1.5.0 Jun 9, 2023
1.4.0 Mar 25, 2023
0.9.1 Jul 20, 2018

#41 in Date and time

Download history 3795/week @ 2024-08-23 3857/week @ 2024-08-30 3571/week @ 2024-09-06 3246/week @ 2024-09-13 3345/week @ 2024-09-20 3137/week @ 2024-09-27 2929/week @ 2024-10-04 3501/week @ 2024-10-11 3648/week @ 2024-10-18 2874/week @ 2024-10-25 3419/week @ 2024-11-01 3187/week @ 2024-11-08 3246/week @ 2024-11-15 2912/week @ 2024-11-22 3951/week @ 2024-11-29 2884/week @ 2024-12-06

13,534 downloads per month
Used in 24 crates (6 directly)

Apache-2.0

150KB
4K SLoC

dtparse

crates.io docs.rs

The fully-featured "even I couldn't understand that" time parser. Designed to take in strings and give back sensible dates and times.

dtparse has its foundations in the dateutil library for Python, which excels at taking "interesting" strings and trying to make sense of the dates and times they contain. A couple of quick examples from the test cases should give some context:

extern crate chrono;
extern crate dtparse;
use chrono::prelude::*;
use dtparse::parse;

assert_eq!(
    parse("2008.12.30"),
    Ok((NaiveDate::from_ymd(2008, 12, 30).and_hms(0, 0, 0), None))
);

// It can even handle timezones!
assert_eq!(
    parse("January 4, 2024; 18:30:04 +02:00"),
    Ok((
        NaiveDate::from_ymd(2024, 1, 4).and_hms(18, 30, 4),
        Some(FixedOffset::east(7200))
    ))
);

And we can even handle fuzzy strings where dates/times aren't the only content if we dig into the implementation a bit!

extern crate chrono;
extern crate dtparse;
use chrono::prelude::*;
use dtparse::Parser;
use std::collections::HashMap;

let mut p = Parser::default();
assert_eq!(
    p.parse(
        "I first released this library on the 17th of June, 2018.",
        None, None,
        true /* turns on fuzzy mode */,
        true /* gives us the tokens that weren't recognized */,
        None, false, &HashMap::new()
    ),
    Ok((
        NaiveDate::from_ymd(2018, 6, 17).and_hms(0, 0, 0),
        None,
        Some(vec!["I first released this library on the ",
                  " of ", ", "].iter().map(|&s| s.into()).collect())
    ))
);

Further examples can be found in the examples directory on international usage.

Usage

dtparse requires a minimum Rust version of 1.28 to build, but is tested on Windows, OSX, BSD, Linux, and WASM. The build is also compiled against the iOS and Android SDK's, but is not tested against them.

Dependencies

~1.5–6.5MB
~35K SLoC