Skip to content

Commit

Permalink
fixup to #51743, timetype subtraction
Browse files Browse the repository at this point in the history
Restores the method whose removal was probably causing problems.
  • Loading branch information
JeffBezanson committed Oct 26, 2023
1 parent 837522a commit f6f1ee9
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 f6f1ee9

Please sign in to comment.