Skip to content

Commit f6f1ee9

Browse files
committed
fixup to #51743, timetype subtraction
Restores the method whose removal was probably causing problems.
1 parent 837522a commit f6f1ee9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

stdlib/Dates/src/arithmetic.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
# TimeType arithmetic
88
(+)(x::TimeType) = x
9-
(-)(x::Date, y::Date) = x.instant - y.instant
10-
(-)(x::Time, y::Time) = x.instant - y.instant
9+
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
1110
(-)(x::DateTime, y::DateTime) = x.instant - y.instant
1211
(-)(x::AbstractDateTime, y::AbstractDateTime) = -(promote(x, y)...)
1312

stdlib/Dates/test/arithmetic.jl

+5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ using Dates
1111
@test Dates.CompoundPeriod(a - b) == Dates.Hour(12)
1212
end
1313

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

1823
@testset "Wrapping arithmetic for Months" begin

0 commit comments

Comments
 (0)