I have a series of date strings of the form "01 Feb"
, "02 Feb"
. I am trying to parse these as Date
objects, except it fails as it doesn’t recognize that there were 29 days in Feb this year. Since the year is not specified in the date strings, is there a way to get around this?
Here is what I’m trying:
julia> Date("29 Feb",dateformat"d u")
ERROR: ArgumentError: Day: 29 out of range (1:28)
Stacktrace:
[1] Date(::Int64, ::Int64, ::Int64) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Dates/src/types.jl:223
[2] parse at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Dates/src/parse.jl:285 [inlined]
[3] Date(::String, ::DateFormat{Symbol("d u"),Tuple{Dates.DatePart{'d'},Dates.Delim{Char,1},Dates.DatePart{'u'}}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Dates/src/io.jl:503
[4] top-level scope at REPL[16]:1
while this works:
julia> Date("29 Feb 2020",dateformat"d u Y")
2020-02-29
So one way to solve this is to append the year to the strings and then convert. I was wondering if there is a flag that I might provide to the constructor to treat the dates as a leap year without having to alter the strings?