Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse a year string with DateTime #52989

Closed
guilhermebodin opened this issue Jan 21, 2024 · 1 comment · Fixed by #53954
Closed

Cannot parse a year string with DateTime #52989

guilhermebodin opened this issue Jan 21, 2024 · 1 comment · Fixed by #53954

Comments

@guilhermebodin
Copy link

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.
@guilhermebodin
Copy link
Author

For reference, @quinnj posted on Slack that this snippet works

julia> parse(DateTime, "2000", dateformat"yyyy-mm-dd\\THH:MM:SS.s")
2000-01-01T00:00:00

but the simpler syntax version does not.

Viriato5 added a commit to Viriato5/julia that referenced this issue Mar 28, 2024
Viriato5 pushed a commit to Viriato5/julia that referenced this issue Mar 29, 2024
Viriato5 added a commit to Viriato5/julia that referenced this issue Mar 29, 2024
@quinnj quinnj closed this as completed in 821c608 Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant