Closed softdevca closed 9 months ago
For a little more background: A test was failing occasionally because code that was parsing the result of OffsetDateTime::now_utc().to_string()
would start to fail around midnight UTC.
Single digit hours can be parsed. You need to explicitly ask for that, as the default is to have them padded with zeroes. This is indicated in the documentation. More generally, you should use a format description for clarity rather than relying on the Display
implementation if you are expecting a specific format. The output of Display
is permitted to change without warning.
Submitted PR to the book to clarify padding.
The default Display implementation for
Time
andOffsetDateTime
cannot reliably be parsed by a format description because the hour is not always two digits.The root issues seems to be that in
parsing/component.rs
the following function requires the hour field be two digits, where the display implementation ofTime
does not pad to two digit hours:I suggest that single digit hours be permitted. A more general solution would be to enable format descriptions to indicate which fields may be single digits.