Skip to content

Commit 405ce11

Browse files
authored
further fix to the new promoting method for AbstractDateTime subtraction (#51967)
1 parent e2a6424 commit 405ce11

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

stdlib/Dates/src/arithmetic.jl

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

1313
# Date-Time arithmetic

stdlib/Dates/test/arithmetic.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ end
1414
struct MonthlyDate <: TimeType
1515
instant::Dates.UTInstant{Month}
1616
end
17+
struct OtherTime <: Dates.AbstractDateTime
18+
instant::Dates.UTInstant{Nanosecond}
19+
end
1720
@testset "TimeType arithmetic" begin
1821
@test_throws MethodError DateTime(2023, 5, 2) - Date(2023, 5, 1)
1922
# check that - between two same-type TimeTypes works by default
2023
@test MonthlyDate(Dates.UTInstant(Month(10))) - MonthlyDate(Dates.UTInstant(Month(1))) == Month(9)
24+
# ... and between two same-type AbstractDateTimes
25+
@test OtherTime(Dates.UTInstant(Nanosecond(2))) - OtherTime(Dates.UTInstant(Nanosecond(1))) == Nanosecond(1)
2126
end
2227

2328
@testset "Wrapping arithmetic for Months" begin

0 commit comments

Comments
 (0)