chrono icon indicating copy to clipboard operation
chrono copied to clipboard

Allow default values when parsing, and error on unused fields

Open pitdicker opened this issue 2 years ago • 1 comments
trafficstars

Default values when parsing

NaiveTime: When parsing seconds and nanoseconds may already be omitted. This is now extended to minutes.

NaiveDate: When a day field is missing, default to the first day of the month when parsing year-month-day, or default to the first day of the week when parsing year-week-weekday. If there are multiple choices, such as when there is no day field but both a month and week field, we don't arbitrarily pick a default.

NaiveDateTime: Uses the combination of fallbacks from NaiveTime and NaiveDate. And if hour is missing, defaults that to zero also.

DateTime: No changes. Only seconds and nanoseconds may be omitted.

Error on unused fields

  • NaiveTime errors if there are any date fields or an offset present.
  • NaiveDate errors if there are any time fields or an offset present.
  • NaiveDateTime errors if there is an offset present.

The various choices here are relatively easy to change. We could for example make NaiveDateTime require a full date and at least an hour.

Fixes https://github.com/chronotope/chrono/issues/528, https://github.com/chronotope/chrono/issues/961. cc @MarcoGorelli

pitdicker avatar May 28 '23 14:05 pitdicker

I have removed the part from this PR to error on unused fields. Now it should accept strictly more strings as valid when parsing, so it should be good for the 0.4.x branch.

I will open a follow up PR against main if this is merged.

pitdicker avatar Jun 12 '23 08:06 pitdicker