From 6778bef3ad8bfe94a37596c9271af42e59fe13fa Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Tue, 27 Nov 2018 15:33:35 -0600 Subject: [PATCH] Set TimeZones as scalars for broadcasting (#30159) --- stdlib/Dates/src/arithmetic.jl | 3 ++- stdlib/Dates/test/arithmetic.jl | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/Dates/src/arithmetic.jl b/stdlib/Dates/src/arithmetic.jl index 0b9ece4f27e1e..5bbf6972c3141 100644 --- a/stdlib/Dates/src/arithmetic.jl +++ b/stdlib/Dates/src/arithmetic.jl @@ -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) diff --git a/stdlib/Dates/test/arithmetic.jl b/stdlib/Dates/test/arithmetic.jl index 487cb8627b6b7..266884f45b0a6 100644 --- a/stdlib/Dates/test/arithmetic.jl +++ b/stdlib/Dates/test/arithmetic.jl @@ -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