# Method of Base.:+ defined for times but not ints?

**URL:** <https://discourse.julialang.org/t/method-of-base-defined-for-times-but-not-ints/98818>\
**Category:** New to Julia\
**Created:** [May 13, 2023, 11:39pm UTC](https://discourse.julialang.org/t/method-of-base-defined-for-times-but-not-ints/98818 "2023-05-13T23:39:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![freeman](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@freeman](https://discourse.julialang.org/u/freeman)\
**Post date:** [May 13, 2023, 11:39pm UTC](https://discourse.julialang.org/t/method-of-base-defined-for-times-but-not-ints/98818/1 "2023-05-13T23:39:31Z")

</div>

Just an observation.

This isn’t defined

```julia
[1] + 1
# ERROR: MethodError: no method matching +(::Vector{Int64}, ::Int64)

```

But this is

```julia
[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.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [May 13, 2023, 11:45pm UTC](https://discourse.julialang.org/t/method-of-base-defined-for-times-but-not-ints/98818/2 "2023-05-13T23:45:54Z")

</div>

```julia
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.

---

<div class="post-metadata">

**Author:** ![freeman](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@freeman](https://discourse.julialang.org/u/freeman)\
**Post date:** [May 13, 2023, 11:55pm UTC](https://discourse.julialang.org/t/method-of-base-defined-for-times-but-not-ints/98818/3 "2023-05-13T23:55:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 14, 2023, 12:04am UTC](https://discourse.julialang.org/t/method-of-base-defined-for-times-but-not-ints/98818/4 "2023-05-14T00:04:57Z")

</div>

```julia
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
julia> [DateTime(2023,1,1)] .+ Second(1) 1-element Vector{DateTime}:        
2023-01-01T00:00:01
                                  
julia> [1] .+ 1                   
1-element Vector{Int64}:           
2

```
