Skip to content

Conversation

@omus
Copy link
Member

@omus omus commented May 21, 2024

Follow up to #53981. Fixes an issue introduced with negative years and fixed-with date formats:

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.

@omus omus requested a review from quinnj May 21, 2024 16:46
@omus omus added the dates Dates, times, and the Dates stdlib module label May 21, 2024
@quinnj quinnj merged commit 263928f into master May 21, 2024
@quinnj quinnj deleted the cv/negative-fixed-year branch May 21, 2024 19:54
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

Labels

dates Dates, times, and the Dates stdlib module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants