Skip to content

Commit

Permalink
Set TimeZones as scalars for broadcasting (#30159)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamed2 authored and ararslan committed Nov 27, 2018
1 parent 7acacfc commit 6778bef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stdlib/Dates/src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ end
(-)(x::OrdinalRange{T}, y::OrdinalRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)
(-)(x::AbstractRange{T}, y::AbstractRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)

# Allow dates and times to broadcast as unwrapped scalars
# Allow dates, times, and time zones to broadcast as unwrapped scalars
Base.Broadcast.broadcastable(x::AbstractTime) = Ref(x)
Base.Broadcast.broadcastable(x::TimeZone) = Ref(x)
4 changes: 4 additions & 0 deletions stdlib/Dates/test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ end
@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) - t1
@test_throws MethodError (Dates.Hour(1) + Dates.Minute(1)) - t3
end
@testset "TimeZone" begin
# best we can get in Dates as there is no other tz functionality
@test ((a, b) -> now(typeof(a))).(UTC(), [1,2,3]) isa Vector{DateTime}
end
end

end

0 comments on commit 6778bef

Please sign in to comment.