Skip to content

Commit e7425d5

Browse files
authored
TimeType subtraction using promote (#49700)
1 parent 61f6082 commit e7425d5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

stdlib/Dates/src/arithmetic.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# TimeType arithmetic
88
(+)(x::TimeType) = x
99
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
10+
(-)(x::TimeType, y::TimeType) = -(promote(x, y)...)
1011

1112
# Date-Time arithmetic
1213
"""

stdlib/Dates/test/arithmetic.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ using Dates
1010
b = Dates.Time(11, 59, 59)
1111
@test Dates.CompoundPeriod(a - b) == Dates.Hour(12)
1212
end
13+
14+
@testset "TimeType arithmetic" begin
15+
a = Date(2023, 5, 1)
16+
b = DateTime(2023, 5, 2)
17+
@test b - a == Day(1)
18+
end
19+
1320
@testset "Wrapping arithmetic for Months" begin
1421
# This ends up being trickier than expected because
1522
# the user might do 2014-01-01 + Month(-14)

0 commit comments

Comments
 (0)