GithubHelp home page GithubHelp logo

Comments (3)

waltzofpearls avatar waltzofpearls commented on June 10, 2024

Yes. I think parse_with function will help you do that.

Below is an example showing you how to pass a default time to the function call. To replicate what Joda does, you can call dateparser::parse_with("2021-12-02", &chrono::offset::Utc, chrono::naive::NaiveTime::from_hms(0, 0, 0))?, and it should return 2021-12-02T00:00:00Z as type chrono::DateTime<chrono::offset::Utc>.

use chrono::{
    naive::NaiveTime,
    offset::{Local, Utc},
};
use dateparser::parse_with;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let parsed_in_local = parse_with("2021-10-09", &Local, NaiveTime::from_hms(0, 0, 0))?;
    println!("{:#?}", parsed_in_local);

    let parsed_in_utc = parse_with("2021-10-09", &Utc, NaiveTime::from_hms(0, 0, 0))?;
    println!("{:#?}", parsed_in_utc);

    Ok(())
}

Since that example is in the repo, you can run it with cargo run --example parse_with.

For future v1 release, I'm going to make 00:00:00Z as default time for parse function, so it will be aligned with date parser libraries from other languages.

from dateparser.

nheitz avatar nheitz commented on June 10, 2024

Brilliant. How nice when the API already caters for the need at hand! I appreciate your response...I was in despair with the rigidity of the base chrono offerings before I discovered this library.

from dateparser.

waltzofpearls avatar waltzofpearls commented on June 10, 2024

I couldn't agree more. I struggled when writing this library with chrono's docs, as it only has examples for common use cases. I had to read chrono source code to figure out how to made it doing things I wanted.

I will leave this issue open for 24 hours in case if you have further questions.

from dateparser.

Related Issues (12)

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.