Go to file
Michel Alexandre Salim 49a8a70bea
Don't ship Python scripts
This complicates distribution packaging in Fedora as the presence of these
files led the dependency generator to assume the crate depends on Python

```
michel in dtparse on  dont-ship-python is 📦 v1.4.0 via 🐍 v3.11.3 via 🦀 v1.69.0 took 6s
⬢ [fedora-toolbox:38] ❯ cargo package --allow-dirty --no-verify
   Packaging dtparse v1.4.0 (/home/michel/src/github/bspeice/dtparse)
    Updating crates.io index
    Packaged 19 files, 175.0KiB (30.7KiB compressed)

michel in dtparse on  dont-ship-python is 📦 v1.4.0 via 🐍 v3.11.3 via 🦀 v1.69.0 took 2s
⬢ [fedora-toolbox:38] ❯ tar tf target/package/dtparse-1.4.0.crate | grep '.py'
dtparse-1.4.0/build_pycompat.py
dtparse-1.4.0/build_pycompat_tokenizer.py
```

```
michel in dtparse on  dont-ship-python [!] is 📦 v1.4.0 via 🐍 v3.11.3 via 🦀 v1.69.0 took 9s
⬢ [fedora-toolbox:38] ❯ cargo package --allow-dirty --no-verify
   Packaging dtparse v1.4.0 (/home/michel/src/github/bspeice/dtparse)
    Updating crates.io index
    Packaged 17 files, 157.4KiB (27.4KiB compressed)

michel in dtparse on  dont-ship-python [!] is 📦 v1.4.0 via 🐍 v3.11.3 via 🦀 v1.69.0
⬢ [fedora-toolbox:38] ❯ tar tf target/package/dtparse-1.4.0.crate | grep '\.py'

michel in dtparse on  dont-ship-python [!] is 📦 v1.4.0 via 🐍 v3.11.3 via 🦀 v1.69.0
⬢ [fedora-toolbox:38] ❯
```

Signed-off-by: Michel Alexandre Salim <salimma@fedoraproject.org>
2023-06-09 14:31:39 -05:00
examples Fix deprecations 2023-03-25 02:29:55 +00:00
src Fix deprecations 2023-03-25 02:29:55 +00:00
.gitignore Test adding WASM support 2018-08-14 21:53:35 -04:00
CHANGELOG.md Release version 1.0.3 2018-09-18 23:04:07 -04:00
CONTRIBUTING.md Remove fuzzing, add CONTRIBUTING/CONTRIBUTORS 2018-07-24 22:41:56 -04:00
CONTRIBUTORS.md Add one final CONTRIBUTOR 2018-08-03 23:43:24 -04:00
Cargo.toml Don't ship Python scripts 2023-06-09 14:31:39 -05:00
LICENSE Licensing/docs updates 2018-06-17 23:31:25 -04:00
README.md #40: Nanosecond precision 2023-03-25 02:12:57 +00:00
build_pycompat.py Fix deprecations 2023-03-25 02:29:55 +00:00
build_pycompat_tokenizer.py Remove a last println and use a static default parser 2018-09-17 23:14:50 -04:00

README.md

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.