-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: BSON
-
None
The bson_datetime_as_iso_string serde helper uses chrono::DateTime's Display functionality to produce a string, but this string is not properly ISO-8601 formatted. We should instead use DateTime::to_rfc3339 to explicitly ensure the output format of our strings. Likewise, the helpers that deserialize from strings use parse_str, which means non-ISO formatted strings will be deserialized when they should produce errors. We should restrict this by using parse_from_rfc3339.
e.g. this test uses the following date, which is not valid according to either ISO-8601 or RFC 3339:
1996-12-20 00:39:57 UTC
I verified this doesn't match using Swift's ISO8601DateFormatter.
On a related note, we should update the names of these helpers to be more specific about which standard they're following to help avoid a similar issue from happening in the future. e.g. we could name the helper rfc3339_string_as_bson_datetime, since that will be the one we actually use from chrono.