Just an observation.
This isn’t defined
[1] + 1
# ERROR: MethodError: no method matching +(::Vector{Int64}, ::Int64)
But this is
[DateTime(2023,1,1)] + Second(1)
# 1-element Vector{DateTime}:
# 2023-01-01T00:00:01
I don’t have an opinion on what the behavior should be, It’s just surprising to see different behaviors.
jar1
May 13, 2023, 11:45pm
2
function (+)(x::AbstractArray{<:TimeType}, y::GeneralPeriod)
# depwarn("non-broadcasted arithmetic is deprecated for Dates.TimeType; use broadcasting instead", nothing)
x .+ y
end
Looks like the deprecation is commented out.
1 Like
Sounds like I shouldn’t use it then. Thank you.
Care to tell me how you found this?
I know of methods(Base.:+)
, but that displays like 200 methods.
mkitti
May 14, 2023, 12:04am
4
julia> @which [DateTime(2023,1,1)] + Second(1)
+(x::AbstractArray{<:TimeType}, y::Union{Dates.CompoundPeriod, Period})
@ Dates ~/julia-1.9.0-rc2/share/julia/stdlib/v1.9/Dates/src/deprecated.jl:6
julia> @less [DateTime(2023,1,1)] + Second(1)
Just to make sure, the right way to do this is via broadcasting or maybe map.
julia> [DateTime(2023,1,1)] .+ Second(1) 1-element Vector{DateTime}:
2023-01-01T00:00:01
julia> [1] .+ 1
1-element Vector{Int64}:
2
5 Likes