Skip to content

Commit 6778bef

Browse files
iamed2ararslan
authored andcommitted
Set TimeZones as scalars for broadcasting (#30159)
1 parent 7acacfc commit 6778bef

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

stdlib/Dates/src/arithmetic.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,6 @@ end
8383
(-)(x::OrdinalRange{T}, y::OrdinalRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)
8484
(-)(x::AbstractRange{T}, y::AbstractRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)
8585

86-
# Allow dates and times to broadcast as unwrapped scalars
86+
# Allow dates, times, and time zones to broadcast as unwrapped scalars
8787
Base.Broadcast.broadcastable(x::AbstractTime) = Ref(x)
88+
Base.Broadcast.broadcastable(x::TimeZone) = Ref(x)

stdlib/Dates/test/arithmetic.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ end
472472
@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) - t1
473473
@test_throws MethodError (Dates.Hour(1) + Dates.Minute(1)) - t3
474474
end
475+
@testset "TimeZone" begin
476+
# best we can get in Dates as there is no other tz functionality
477+
@test ((a, b) -> now(typeof(a))).(UTC(), [1,2,3]) isa Vector{DateTime}
478+
end
475479
end
476480

477481
end

0 commit comments

Comments
 (0)