-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix Date parsing crash when parsing a negative year #53981
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quinnj
reviewed
Apr 6, 2024
stdlib/Dates/test/io.jl
Outdated
Comment on lines
625
to
630
try | ||
Date("") | ||
@test false | ||
catch err | ||
@test err.msg == "Cannot parse an empty string as a Date or Time" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary?
vtjnash
reviewed
Apr 6, 2024
stdlib/Dates/test/io.jl Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Bump. |
Hi, sorry for the delay. |
@quinnj Good to merge? |
quinnj
approved these changes
May 21, 2024
This was referenced May 21, 2024
quinnj
pushed a commit
that referenced
this pull request
May 21, 2024
Follow up to #53981. Fixes an issue introduced with negative years and fixed-with date formats: ```julia julia> Dates.DateTime("-20240521", "yyyymmdd") ERROR: ArgumentError: Month: 40 out of range (1:12) Stacktrace: [1] DateTime(y::Int64, m::Int64, d::Int64, h::Int64, mi::Int64, s::Int64, ms::Int64, ampm::Dates.AMPM) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/types.jl:246 [2] parse(::Type{DateTime}, str::String, df::DateFormat{:yyyymmdd, Tuple{Dates.DatePart{'y'}, Dates.DatePart{'m'}, Dates.DatePart{'d'}}}) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/parse.jl:294 [3] DateTime(dt::String, format::String; locale::Dates.DateLocale) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/io.jl:555 [4] DateTime(dt::String, format::String) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/io.jl:554 [5] top-level scope @ REPL[4]:1 ``` This PR makes it so that fixed-width formats require the specified number of digits. I also decided to only add the sign parsing for years to running into performance issues with parsing sign information where it isn't expected.
lazarusA
pushed a commit
to lazarusA/julia
that referenced
this pull request
Jul 12, 2024
Fixes JuliaLang#50328. Originally checked on version 1.10.0 but still relevant in the current version in master Bug: In method Date(str), when given a negative year as an argument (ex: "-2000"), it would output an error while in Date(int) once given a negative year (ex: "-2000") it would work as intended returning "-2000-01-01". Fix: In function tryparsenext_base10 the character '-' wasn't being accounted so i check if it existed in the first iteration of the string and if yes I would multiply the output * -1. Test: Added some tests that verify this specific Fix. --------- Co-authored-by: Jameson Nash <vtjnash@gmail.com> Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
lazarusA
pushed a commit
to lazarusA/julia
that referenced
this pull request
Jul 12, 2024
Follow up to JuliaLang#53981. Fixes an issue introduced with negative years and fixed-with date formats: ```julia julia> Dates.DateTime("-20240521", "yyyymmdd") ERROR: ArgumentError: Month: 40 out of range (1:12) Stacktrace: [1] DateTime(y::Int64, m::Int64, d::Int64, h::Int64, mi::Int64, s::Int64, ms::Int64, ampm::Dates.AMPM) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/types.jl:246 [2] parse(::Type{DateTime}, str::String, df::DateFormat{:yyyymmdd, Tuple{Dates.DatePart{'y'}, Dates.DatePart{'m'}, Dates.DatePart{'d'}}}) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/parse.jl:294 [3] DateTime(dt::String, format::String; locale::Dates.DateLocale) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/io.jl:555 [4] DateTime(dt::String, format::String) @ Dates ~/Development/Julia/aarch64/latest/usr/share/julia/stdlib/v1.12/Dates/src/io.jl:554 [5] top-level scope @ REPL[4]:1 ``` This PR makes it so that fixed-width formats require the specified number of digits. I also decided to only add the sign parsing for years to running into performance issues with parsing sign information where it isn't expected.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #50328.
Originally checked on version 1.10.0 but still relevant in the current version in master
Bug: In method Date(str), when given a negative year as an argument (ex: "-2000"), it would output an error while in Date(int) once given a negative year (ex: "-2000") it would work as intended returning "-2000-01-01".
Fix: In function tryparsenext_base10 the character '-' wasn't being accounted so i check if it existed in the first iteration of the string and if yes I would multiply the output * -1.
Test: Added some tests that verify this specific Fix.