time-rs / time

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

year repr:last_two removed in 0.3.x? #662

Closed snspinn closed 4 months ago

snspinn commented 4 months ago

Is the repr:last_two year component formatting option removed from latest? I'm manipulating a string in the form of "YYMMDDmm" into OffsetDateTime.

I've found that the following input and description work when passed into OffsetDateTime::parse():

let input = format!("20{}00 +00:00:00",date_time_period);
let description = format_description!("[year][month repr:numerical][day][hour repr:24][minute][second] \
                                        [offset_hour sign:mandatory]:[offset_minute]:[offset_second]");

But these inputs are failing with a TryFromParsed(InsufficientInformation):

let input = format!("{}00 +00:00:00",date_time_period);
let description = format_description!("[year repr:last_two][month repr:numerical][day][hour repr:24][minute][second] \
                                        [offset_hour `sign:mandatory]:[offset_minute]:[offset_second]");

If I print out the input and description in the failing case, I get the following (suggesting it should work):

"230909220000 +00:00:00"
[Year(Year { padding: Zero, repr: LastTwo, iso_week_based: false, sign_is_mandatory: false }), Month(Month { padding: Zero, repr: Numerical, case_sensitive: true }), Day(Day { padding: Zero }), Hour(Hour { padding: Zero, is_12_hour_clock: false }), Minute(Minute { padding: Zero }), Second(Second { padding: Zero }),  , OffsetHour(OffsetHour { sign_is_mandatory: true, padding: Zero }), :, OffsetMinute(OffsetMinute { padding: Zero }), :, OffsetSecond(OffsetSecond { padding: Zero })]

Versions

rustc 1.75.0 (82e1608df 2023-12-21) time = { version = "0.3.34", features = ["macros", "parsing"] }

jhpratt commented 4 months ago

It was not removed; it was never supported. See #649 for details.