Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse returns datetime with time set to current local time #19

Closed
deankarn opened this issue Nov 5, 2021 · 2 comments
Closed

parse returns datetime with time set to current local time #19

deankarn opened this issue Nov 5, 2021 · 2 comments

Comments

@deankarn
Copy link

deankarn commented Nov 5, 2021

Reviving #16

I was wondering if you would consider adding a feature or accepting a PR to allow zeroing out of unknown components?

My use case is I wish to use this parser to parse arbitrary dates where adding the local time makes the dates incorrect. Because I'll be parsing arbitrary data where the input is not under my direct control I will be unable to implement the workaround provided in the previous issue.

@waltzofpearls
Copy link
Owner

waltzofpearls commented Nov 6, 2021

Would this work you? https://github.com/waltzofpearls/belt/blob/main/dateparser/examples/parse_with.rs

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(())
}

It printed the following at the time I ran it.

2021-10-10T00:00:00Z
2021-10-09T00:00:00Z

Both zero out time. The difference is the first one assumes it's a local date, and the second parses the date with UTC.

@deankarn
Copy link
Author

deankarn commented Nov 8, 2021

@waltzofpearls unfortunately this would not resolve my issue, the core of the issue is setting unknown parts of a DateTime with the current Local or UTC time rather than zeroing them out.

Thanks for your time, I think I'm going to invest some time in a more custom solution for now.

@deankarn deankarn closed this as completed Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants