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 custom format without minutes, behavior inconsistent with seconds #603

Closed GunnarMorrigan closed 1 year ago

GunnarMorrigan commented 1 year ago

I want to be able to parse a custom format and let time fill in any other information as 0.

    let format = time::macros::format_description!(
        "[year]-[month]-[day]_[hour]"
    );

    PrimitiveDateTime::parse("2023-05-12_19", &format)

Time crate currently returns 'the Parsed struct did not include enough information to construct the type' This is technically right but it should fill in the blanks with 0. This is also actual behavior that the time crate already performs. If I add just the minute "2023-05-12_19_00" with format "[year]-[month]-[day]_[hour]_[minute]" then it works fine and sets seconds to 0.

The seconds are also missing from my format but why are they initialized to 0 and minutes do not do this? This is inconsistent behavior.

jhpratt commented 1 year ago

In what situation is this format used? I have never encountered a time that only has the hours present (when not presented as a range, such as shop hours). The exception is for things like "1 PM", which is parsed successfully.

The reason I ask is because I only support parsing combinations that exist and are routinely used.

Zercerium commented 1 year ago

just for reference #590 the DWD uses sometimes this format but there data shemas are really messed up sometimes 🙈

STATIONS_ID;MESS_DATUM;QN_8;  R1;RS_IND;WRTR;eor
3;1995090100;    1;   0.0;   0;-999;eor
jhpratt commented 1 year ago

As someone who has handled raw weather data before, I'm quite surprised that they opted to omit the minutes, as that's definitely relevant information. Regardless, that's sufficient for me. I'll add in support when I get a chance.

jhpratt commented 1 year ago

Done in #604.