chrono
chrono copied to clipboard
Allow default values when parsing, and error on unused fields
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
NaiveTimeerrors if there are any date fields or an offset present.NaiveDateerrors if there are any time fields or an offset present.NaiveDateTimeerrors 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
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.