time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.13k stars 281 forks source link

parsing a date with a year with last_two #712

Closed JL710 closed 1 month ago

JL710 commented 1 month ago

I am trying to parse this date 30.09.24 with this code:

time::Date::parse(
    date,
    &time::format_description::parse("[day].[month].[year repr:last_two]")
        .context("Could not create format description")?,
)
.context("Could not parse date")?

I am getting this error:

the `Parsed` struct did not include enough information to construct the type

I have no idea what I am doing wrong here.

jhpratt commented 1 month ago

The last two digits of a year do not unambiguously identify what year should be used.

JL710 commented 1 month ago

The last two digits of a year do not unambiguously identify what year should be used.

Maybe there could be a way to add additional info about the year so that it works.

jhpratt commented 1 month ago

You can go through the Parsed struct manually, setting the full year while using the information from the two digits.