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
Raw File
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
.clang-format
Language: Cpp
Standard: Cpp11
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Stroustrup
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeColon
BreakConstructorInitializersBeforeComma: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: false
ColumnLimit: 92
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
IncludeBlocks: Preserve
IncludeCategories:
  - Regex:           '^(<|"(llvm|llvm-c|clang|clang-c)/)'
    Priority:        2
  - Regex:           '^<.*'
    Priority:        3
  - Regex:           '.*'
    Priority:        1
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 8
UseCRLF: true
UseTab: Never
ForEachMacros:
  - JL_TRY
  - JL_CATCH
StatementMacros:
  - bi_fintrinsic
  - bi_iintrinsic_fast
  - bi_intrinsic_ctype
  - bool_fintrinsic
  - bool_iintrinsic_fast
  - bool_intrinsic_ctype
  - checked_intrinsic_ctype
  - cvt_iintrinsic
  - fpiseq_n
  - ter_fintrinsic
  - ter_intrinsic_ctype
  - un_fintrinsic
  - un_fintrinsic_withtype
  - un_iintrinsic_ctype
  - uu_iintrinsic_ctype
back to top