Hi, I tried to use Dates module and divide Millseconds on Minutes and error happen.
Why operation didn’t dispatch to method " /(::P, ::P) where P<:Period" ?
Julia Version 1.6.5
julia> using Dates
julia> Dates.Millisecond(60_000) / Dates.Minute(1)
ERROR: MethodError: no method matching /(::Millisecond, ::Minute)
Closest candidates are:
/(::StridedArray{P, N} where N, ::P) where P<:Period at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Dates\src\deprecated.jl:44
/(::AbstractRange{var"#s814"} where var"#s814"<:P, ::P) where P<:Period at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Dates\src\ranges.jl:67
/(::P, ::P) where P<:Period at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Dates\src\periods.jl:82
...
Stacktrace:
[1] top-level scope
@ REPL[2]:1
julia> Dates.Millisecond(60_000) isa Dates.Period
true
julia> Dates.Minute(1) isa Dates.Period
true
Ouch, I see, the method definition " /(::P, ::P) where P<:Period" means that both arguments must be not just subtypes of Period, but also have exactly the same type which is not the case.
P.S. Until Julia 1.8, I decided to use in my code “/(promote(x,y)…)” because ‘x’ and ‘y’ could come in different combinations of Hour, Minute, Second, Millisecond, etc… .
Exactly that’s the intended behavior. Looking at the GitHub issue also shows that Dates definitions are not really convertible to each other’s as easily as you’ll think, but if promoting them works, that’s the right way to go for now.