Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stdlib/Dates/src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# TimeType arithmetic
(+)(x::TimeType) = x
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
(-)(x::TimeType, y::TimeType) = -(promote(x, y)...)

# Date-Time arithmetic
"""
Expand Down
7 changes: 7 additions & 0 deletions stdlib/Dates/test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ using Dates
b = Dates.Time(11, 59, 59)
@test Dates.CompoundPeriod(a - b) == Dates.Hour(12)
end

@testset "TimeType arithmetic" begin
a = Date(2023, 5, 1)
b = DateTime(2023, 5, 2)
@test b - a == Day(1)
end

@testset "Wrapping arithmetic for Months" begin
# This ends up being trickier than expected because
# the user might do 2014-01-01 + Month(-14)
Expand Down