Let's look at the implementation of parse_from_str()
for:
NaiveDateTime:
pub fn parse_from_str(s: &str, fmt: &str) -> ParseResult<NaiveDateTime> {
let mut parsed = Parsed::new();
parse(&mut parsed, s, StrftimeItems::new(fmt))?;
parsed.to_naive_datetime_with_offset(0) // no offset adjustment
}
NaiveDate:
pub fn parse_from_str(s: &str, fmt: &str) -> ParseResult<NaiveDate> {
let mut parsed = Parsed::new();
parse(&mut parsed, s, StrftimeItems::new(fmt))?;
parsed.to_naive_date()
}
Both implementations seem identical, except for the last row. So the Parsed
instance used for the NaiveDate
instance is essentially the same as the one you'd have for the NaiveDateTime
variant. In other words, the whole format was "consumed" the same way, but in the case of NaiveDate
you've basically just used the date part of the date-time value you've parsed.
Not sure what exactly you are looking for, but I hope that info helps.
If you want to just check if you "lost" a "non-zero" time component (00:00:00
) by using NaiveDate
, then I guess you might just parse into a NaiveDateTime
and check if its NaiveTime
value is "zero".