 # Why does this nonbroadcast operation on Day vector give CompoundPeriod?

I get different behavior on `+` and `.+` in the following situation:

``````>foo = Day.([1653, 1618, 1505])
>baz = Day.([7, 7, 7])
>bing = foo.-baz
>bong = foo-baz
>typeof.([foo,baz,bing,bong])
4-element Array{DataType,1}:
Array{Day,1}
Array{Day,1}
Array{Day,1}
Array{Dates.CompoundPeriod,1}
``````

So the last type suggests that a “Day” is not a fixed period which seems maybe true cause leap seconds and that sort of thing but then on the other hand Julia has no problem giving me this:

``````>[f(Day(1)) for f in [Microsecond,Second,Minute]]
3-element Array{TimePeriod,1}:
86400000000 microseconds
86400 seconds
1440 minutes
``````

Is the non-broadcast behavior a bug or is there something I do no understand about usage of `Dates.CompoundPeriod`?

The easiest way to answer this question for yourself is to utilize the `@which` macro at the REPL:

``````julia> a = Day.([1653, 1618, 1505])
3-element Array{Day,1}:
1653 days
1618 days
1505 days

julia> b = Day.([7, 7, 7])
3-element Array{Day,1}:
7 days
7 days
7 days

julia> a-b
3-element Array{Dates.CompoundPeriod,1}:
1646 days
1611 days
1498 days

julia> @which a-b
-(X::Union{DenseArray{#s623,N}, ReinterpretArray{#s623,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray}, ReshapedArray{#s623,N,A,MI} where MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray}, SubArray{#s623,N,A,I,L} where L where I<:Tuple{Vararg{Union{Int64, AbstractRange{Int64}, AbstractCartesianIndex},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, DenseArray}} where N where #s623<:Union{CompoundPeriod, Period}, Y::Union{DenseArray{#s622,N}, ReinterpretArray{#s622,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray}, ReshapedArray{#s622,N,A,MI} where MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray}, SubArray{#s622,N,A,I,L} where L where I<:Tuple{Vararg{Union{Int64, AbstractRange{Int64}, AbstractCartesianIndex},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, ReshapedArray{T,N,A,MI} where MI<:Tuple{Vararg{SignedMultiplicativeInverse{Int64},N} where N} where A<:Union{ReinterpretArray{T,N,S,A} where S where A<:Union{SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, SubArray{T,N,A,I,true} where I<:Union{Tuple{Vararg{Real,N} where N}, Tuple{AbstractUnitRange,Vararg{Any,N} where N}} where A<:DenseArray where N where T, DenseArray} where N where T, DenseArray}} where N where #s622<:Union{CompoundPeriod, Period}) in Dates at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.1/Dates/src/deprecated.jl:64
``````

That may not seem so helpful at first (this is probably the most monstrous type signature I’ve ever come across in Julia), but look at the tail end of `@which`'s output, and you’ll see: `...julia/stdlib/v1.1/Dates/src/deprecated.jl:64`, so that’s where this functionality is defined, if you’d like to look at it yourself. More importantly the filename gives away the fact that this arithmetic on array’s of Dates seems to have been judged not useful (probably too heavy on the operator-punning, if I had to venture a guess), and deprecated.

In other words, I wouldn’t worry about it… your `foo-baz` will be an error in a future version of Julia anyway.

1 Like