Skip to content

Commit

Permalink
fixup to #51743, timetype subtraction (#51881)
Browse files Browse the repository at this point in the history
Restores the method whose removal was probably causing problems.
  • Loading branch information
JeffBezanson authored Oct 31, 2023
1 parent 6084a62 commit 9075731
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions stdlib/Dates/src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

# TimeType arithmetic
(+)(x::TimeType) = x
(-)(x::Date, y::Date) = x.instant - y.instant
(-)(x::Time, y::Time) = x.instant - y.instant
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
(-)(x::DateTime, y::DateTime) = x.instant - y.instant
(-)(x::AbstractDateTime, y::AbstractDateTime) = -(promote(x, y)...)

Expand Down
5 changes: 5 additions & 0 deletions stdlib/Dates/test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ using Dates
@test Dates.CompoundPeriod(a - b) == Dates.Hour(12)
end

struct MonthlyDate <: TimeType
instant::Dates.UTInstant{Month}
end
@testset "TimeType arithmetic" begin
@test_throws MethodError DateTime(2023, 5, 2) - Date(2023, 5, 1)
# check that - between two same-type TimeTypes works by default
@test MonthlyDate(Dates.UTInstant(Month(10))) - MonthlyDate(Dates.UTInstant(Month(1))) == Month(9)
end

@testset "Wrapping arithmetic for Months" begin
Expand Down

0 comments on commit 9075731

Please sign in to comment.