Hello,
The following code raises an error
julia> Date(2020,1,1):Date(2020,2,1)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Day
Closest candidates are:
convert(::Type{Day}, ::Week) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Dates\src\periods.jl:410
convert(::Type{Day}, ::Hour) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Dates\src\periods.jl:418
convert(::Type{Day}, ::Minute) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Dates\src\periods.jl:418
...
Stacktrace:
[1] oftype(::Day, ::Int64) at .\essentials.jl:367
[2] (::Colon)(::Date, ::Date) at .\range.jl:7
[3] top-level scope at REPL[99]:100:
but not
Date(2020,1,1):Dates.Day(1):Date(2020,2,1)
My opinion is that current implementation of range
assume an integer step of 1 but it should assume what a unit step of a Date
is.
I’m facing a similar issue with some custom struct also, not only Date
.
Maybe the default unit step could be calculated in most cases using
julia> start = Date(2020,1,1)
2020-01-01
julia> stop = Date(2020,2,1)
2020-02-01
julia> (stop - start) / (stop - start).value
1 day
or by defining a unit(::Type{Date})
or a unit(::Date)
function
What is you opinion about that?