From f6f1ee9e00b1b9cc1e7703cd4ce7712f7064fdd4 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 25 Oct 2023 20:18:13 -0400 Subject: [PATCH] fixup to #51743, timetype subtraction Restores the method whose removal was probably causing problems. --- stdlib/Dates/src/arithmetic.jl | 3 +-- stdlib/Dates/test/arithmetic.jl | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/Dates/src/arithmetic.jl b/stdlib/Dates/src/arithmetic.jl index 23a76f5ed75d6..b379747c5f9e9 100644 --- a/stdlib/Dates/src/arithmetic.jl +++ b/stdlib/Dates/src/arithmetic.jl @@ -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)...) diff --git a/stdlib/Dates/test/arithmetic.jl b/stdlib/Dates/test/arithmetic.jl index 129e9a60bf490..6e2e89fe32b68 100644 --- a/stdlib/Dates/test/arithmetic.jl +++ b/stdlib/Dates/test/arithmetic.jl @@ -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