Skip to content

Cannot parse a year string with DateTime #52989

Closed
@guilhermebodin

Description

@guilhermebodin

Just came across this behavior and it seemed very odd, could this be a bug or is there a reason for not parsing it?

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0 (2023-12-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Dates

julia> Date("2000")
2000-01-01

julia> DateTime("2000")
ERROR: ArgumentError: Invalid DateTime string
Stacktrace:
 [1] parse(::Type{DateTime}, s::String, df::DateFormat{Symbol("yyyy-mm-dd\\THH:MM:SS.s"), Tuple{…}})
   @ Dates C:\Users\guilhermebodin\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Dates\src\parse.jl:278
 [2] DateTime
   @ Dates C:\Users\guilhermebodin\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Dates\src\io.jl:568 [inlined]
 [3] DateTime(dt::String)
   @ Dates C:\Users\guilhermebodin\.julia\juliaup\julia-1.10.0+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Dates\src\io.jl:568
 [4] top-level scope
   @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions