# Why does Dates allow non-broadcasted arithmatic?

**URL:** <https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205>\
**Category:** General Usage\
**Tags:** dates\
**Created:** [August 10, 2018, 10:49pm UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205 "2018-08-10T22:49:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [August 10, 2018, 10:49pm UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205/1 "2018-08-10T22:49:53Z")

</div>

[https://github.com/JuliaLang/julia/blob/f8d82ccba81223c9d0d43e4077acb2a208bedc7a/stdlib/Dates/src/arithmetic.jl#L94](https://github.com/JuliaLang/julia/blob/f8d82ccba81223c9d0d43e4077acb2a208bedc7a/stdlib/Dates/src/arithmetic.jl#L94)

In the code for Dates there is the following:

```julia
# TimeType, AbstractArray{TimeType}
(-)(x::AbstractArray{T}, y::T) where {T<:TimeType} = x .- y
(-)(y::T, x::AbstractArray{T}) where {T<:TimeType} = y .- x

```

Is this intended? Was it some code to get around deprecation warnings for a period of time?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [August 15, 2018, 5:41pm UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205/2 "2018-08-15T17:41:44Z")

</div>

I imagine this is just an oversight. It should be possible to deprecate it given that Dates is in stdlib. At least it’s worth filing an issue.

---

<div class="post-metadata">

**Author:** ![kevin.squire](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevin.squire/32/62_2.png) [@kevin.squire](https://discourse.julialang.org/u/kevin.squire)\
**Post date:** [October 14, 2018, 3:19am UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205/3 "2018-10-14T03:19:11Z")

</div>

For posterity, the issue is [#28672](https://github.com/JuliaLang/julia/issues/28672).

Cheers,  
Kevin

---

<div class="post-metadata">

**Author:** ![George9000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george9000/32/23619_2.png) [@George9000](https://discourse.julialang.org/u/George9000)\
**Post date:** [November 30, 2021, 3:12am UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205/4 "2021-11-30T03:12:18Z")

</div>

This behavior continues. Reading the issue in the last reply and following links from there to other discussions, date arithmetic yet continues to show ‘auto-broadcasting.’ Upon encountering it last year, as a relative Julia newbie, I was puzzled.

```julia
julia> versioninfo()
Julia Version 1.7.0-rc3
Commit 3348de4ea6 (2021-11-15 08:22 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.1.0)
  CPU: Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, cyclone)
Environment:
  JULIA_EDITOR = Emacs

# dataframe, df, with column named dtime
df.dtime = df.dtime + Dates.Year(1900)
## why don't datetimes need broadcasting syntax?
## 3 + [1, 2, 3] ## error
## 3 .+ [1, 2, 3] ## works

julia> foo
20-element Vector{DateTime}:
 1999-09-01T08:21:00
 1999-08-29T12:28:00
 1999-06-30T09:10:00
 1999-08-08T15:29:00
 1999-07-02T15:17:00
 1999-09-01T08:25:00
 1999-08-29T12:31:00
 1999-06-30T10:56:00
 1999-07-01T10:39:00
 1999-05-25T13:03:00
 1999-05-11T17:11:00
 1999-08-21T02:19:00
 1999-09-01T07:58:00
 1999-08-30T03:51:00
 1997-02-28T17:14:00
 1996-10-01T08:34:00
 1996-09-27T09:13:00
 1996-09-27T12:50:00
 1996-09-27T21:45:00
 1996-09-28T20:20:00

julia> foo + Dates.Year(1)
20-element Vector{DateTime}:
 2000-09-01T08:21:00
 2000-08-29T12:28:00
 2000-06-30T09:10:00
 2000-08-08T15:29:00
 2000-07-02T15:17:00
 2000-09-01T08:25:00
 2000-08-29T12:31:00
 2000-06-30T10:56:00
 2000-07-01T10:39:00
 2000-05-25T13:03:00
 2000-05-11T17:11:00
 2000-08-21T02:19:00
 2000-09-01T07:58:00
 2000-08-30T03:51:00
 1998-02-28T17:14:00
 1997-10-01T08:34:00
 1997-09-27T09:13:00
 1997-09-27T12:50:00
 1997-09-27T21:45:00
 1997-09-28T20:20:00

julia> foo - Dates.Year(1)
20-element Vector{DateTime}:
 1998-09-01T08:21:00
 1998-08-29T12:28:00
 1998-06-30T09:10:00
 1998-08-08T15:29:00
 1998-07-02T15:17:00
 1998-09-01T08:25:00
 1998-08-29T12:31:00
 1998-06-30T10:56:00
 1998-07-01T10:39:00
 1998-05-25T13:03:00
 1998-05-11T17:11:00
 1998-08-21T02:19:00
 1998-09-01T07:58:00
 1998-08-30T03:51:00
 1996-02-28T17:14:00
 1995-10-01T08:34:00
 1995-09-27T09:13:00
 1995-09-27T12:50:00
 1995-09-27T21:45:00
 1995-09-28T20:20:00

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [November 30, 2021, 3:18am UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205/5 "2021-11-30T03:18:59Z")

</div>

[https://github.com/JuliaLang/julia/commit/b8e3b91716c26613c9fc856eb8fa73e77a388e18#diff-af0c0e01cab8cc433de9e334f50c707bef65307401216b6d919ec93c96a3436b](https://github.com/JuliaLang/julia/commit/b8e3b91716c26613c9fc856eb8fa73e77a388e18#diff-af0c0e01cab8cc433de9e334f50c707bef65307401216b6d919ec93c96a3436b)

---

<div class="post-metadata">

**Author:** ![George9000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george9000/32/23619_2.png) [@George9000](https://discourse.julialang.org/u/George9000)\
**Post date:** [November 30, 2021, 3:24am UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205/6 "2021-11-30T03:24:19Z")

</div>

Yes, but see last comment [here](https://github.com/JuliaLang/julia/issues/37814) and [this](https://github.com/JuliaLang/julia/pull/37759#issuecomment-702787433).

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [November 30, 2021, 3:27am UTC](https://discourse.julialang.org/t/why-does-dates-allow-non-broadcasted-arithmatic/13205/7 "2021-11-30T03:27:41Z")

</div>

well yeah we missed it at 1.0 (i.e. 0.7) so there’s nothing we can do now. It’s already been noticed and thus moved to `deprecated.jl`
