https://github.com/JuliaLang/julia
Revision 317211a38947d1d72a7471186490fa9df4944201 authored by Andy Nowacki on 10 November 2022, 22:08:06 UTC, committed by GitHub on 10 November 2022, 22:08:06 UTC
When attempting to construct a `DateTime`, `Date` or `Time` from an
`AbstractString`, throw an `ArgumentError` if the string is empty.
Likewise, error when `parse`ing an empty string as one of these types,
and return `nothing` from `tryparse`.

This behavior differs from previously.  Before, `Date` and `Time` would
return default values of `Date(1)` and `Time(0)`, respectively, while
`DateTime` would error without a `format` argument.  With a `format`
argument, it would return `DateTime(1)`.  However, this appears not to
have been explicitly intended, but rather a consequence of the way
parsing was implemented; no tests for empty string parsing existed.

This addresses #28090 and #43883; see discussion therein.

Summary of changes:
- Check for empty string in `Base.parse(::DateTime)` and throw if so.
- Change documentation to mention this.
- Add a compat notice to the docs contrasting the old behavior.
1 parent e0ba28a
History
Tip revision: 317211a38947d1d72a7471186490fa9df4944201 authored by Andy Nowacki on 10 November 2022, 22:08:06 UTC
Dates: Error on construction/parsing with empty strings (#47117)
Tip revision: 317211a
File Mode Size
CODEOWNERS -rw-r--r-- 209 bytes

back to top