From 32ed45978ee16cb12e4c0cd0f0851e368161918f Mon Sep 17 00:00:00 2001 From: Ben Baumgold <4933671+baumgold@users.noreply.github.com> Date: Sat, 13 May 2023 09:52:41 -0400 Subject: [PATCH 1/2] Limit TimeType subtraction to AbstractDateTime --- stdlib/Dates/src/arithmetic.jl | 2 +- stdlib/Dates/test/arithmetic.jl | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/stdlib/Dates/src/arithmetic.jl b/stdlib/Dates/src/arithmetic.jl index a847f749d0154..813cccf314c57 100644 --- a/stdlib/Dates/src/arithmetic.jl +++ b/stdlib/Dates/src/arithmetic.jl @@ -7,7 +7,7 @@ # TimeType arithmetic (+)(x::TimeType) = x (-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant -(-)(x::TimeType, y::TimeType) = -(promote(x, y)...) +(-)(x::AbstractDateTime, y::AbstractDateTime) = -(promote(x, y)...) # Date-Time arithmetic """ diff --git a/stdlib/Dates/test/arithmetic.jl b/stdlib/Dates/test/arithmetic.jl index 2e684815a3c86..aa7574080186a 100644 --- a/stdlib/Dates/test/arithmetic.jl +++ b/stdlib/Dates/test/arithmetic.jl @@ -11,12 +11,6 @@ using Dates @test Dates.CompoundPeriod(a - b) == Dates.Hour(12) end -@testset "TimeType arithmetic" begin - a = Date(2023, 5, 1) - b = DateTime(2023, 5, 2) - @test b - a == Day(1) -end - @testset "Wrapping arithmetic for Months" begin # This ends up being trickier than expected because # the user might do 2014-01-01 + Month(-14) From ff6dbb3ac9151851304801373db33403adf8602d Mon Sep 17 00:00:00 2001 From: Ben Baumgold <4933671+baumgold@users.noreply.github.com> Date: Sat, 24 Jun 2023 10:08:28 -0400 Subject: [PATCH 2/2] fix stack overflow --- stdlib/Dates/src/arithmetic.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/Dates/src/arithmetic.jl b/stdlib/Dates/src/arithmetic.jl index 813cccf314c57..83a2873b43409 100644 --- a/stdlib/Dates/src/arithmetic.jl +++ b/stdlib/Dates/src/arithmetic.jl @@ -7,6 +7,7 @@ # TimeType arithmetic (+)(x::TimeType) = x (-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant +(-)(x::T, y::T) where {T<:AbstractDateTime} = x.instant - y.instant (-)(x::AbstractDateTime, y::AbstractDateTime) = -(promote(x, y)...) # Date-Time arithmetic