Skip to content

Parsing IsoWeek from a string #1657

@scootermon

Description

@scootermon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions