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

Parsing IsoWeek from a string #1657

Open
scootermon opened this issue Feb 5, 2025 · 1 comment
Open

Parsing IsoWeek from a string #1657

scootermon opened this issue Feb 5, 2025 · 1 comment

Comments

@scootermon
Copy link

I find myself in the situation where I need to parse ISO weeks quite frequently. Especially when it comes to "manufacturing dates", which are very often given as iso weeks like 2024-W30 or even 202430.

My current workaround is to go through a NaiveDate first:

fn parse_iso_week(s: &str) -> ParseResult<IsoWeek> {
    let date = NaiveDate::parse_from_str(&format!("{s} 1"), "%G-W%V %u").unwrap();
    Ok(date.iso_week())
}

// parse_iso_week("2024-W30")

Do you think it would make sense to add this feature natively to chrono? Unfortunately the Parsed::to_naive_date implementation is quite daunting, otherwise I would've already created a proof of concept PR.

@djc
Copy link
Member

djc commented Feb 11, 2025

I'm happy to review a minimal proposal for this, either as a designed API in this issue or just as a PR.

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