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
.devcontainer
.github
base
cli
contrib
deps
doc
etc
src
stdlib
test
.buildkite-external-version -rw-r--r-- 5 bytes
.clang-format -rw-r--r-- 3.3 KB
.codecov.yml -rw-r--r-- 52 bytes
.git-blame-ignore-revs -rw-r--r-- 294 bytes
.gitattributes -rw-r--r-- 65 bytes
.gitignore -rw-r--r-- 493 bytes
.mailmap -rw-r--r-- 12.1 KB
CITATION.bib -rw-r--r-- 513 bytes
CITATION.cff -rw-r--r-- 940 bytes
CONTRIBUTING.md -rw-r--r-- 23.2 KB
HISTORY.md -rw-r--r-- 349.9 KB
LICENSE.md -rw-r--r-- 1.3 KB
Make.inc -rw-r--r-- 52.1 KB
Makefile -rw-r--r-- 27.9 KB
NEWS.md -rw-r--r-- 10.4 KB
README.md -rw-r--r-- 7.3 KB
THIRDPARTY.md -rw-r--r-- 3.7 KB
VERSION -rw-r--r-- 10 bytes
julia.spdx.json -rw-r--r-- 35.8 KB
sysimage.mk -rw-r--r-- 4.1 KB

README.md

back to top