Giter Club home page Giter Club logo

dtparse's Introduction

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.

dtparse's People

Contributors

bspeice avatar mjmeehan avatar bors[bot] avatar messense avatar michel-slm avatar sbrocket avatar gillespiecd avatar gma2th avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.