Open luoq opened 5 years ago
There are a couple open questions about the best way to do this, I think:
parse_from_str_default(tstr, fmtstr, DefaultTime)
with an enum like enum DafaultTime { Beginning, End }
, which will also allow us to default to the max time, although I'm not sure who needs that. Advantage: I think this is the most convenient api.parse_from_str_partial(tstr, fmtstr) -> TimestampFields
where the timestamp fields contains Option<u8>
for most fields. While verbose, this will allow building with something like DateTime::from_ymd(fields.year.unwrap_or(1970), fields.month.unwrap_or(..), ..etc)`. Advantage: this is the most flexible.I'd like something similar for NaiveDate, to default month/day to 1 if they are not given. I'm trying to deserialize a date field from a json API which sometimes returns just a year. Or maybe it would make sense to make a new type, like LaxDate/LaxDateTime or PartialDate/PartialDateTime? NaiveDateTimeWithDefaults? I dunno, maybe someone has a better idea?
output:
Why not just treat missing field as zero