Skip to content

Commit 49dae41

Browse files
authored
add deprecated message for duration (#102)
1 parent 8e74a68 commit 49dae41

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/IntervalSets.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,18 @@ clamp(t, i::TypedEndpointsInterval{:closed,:closed}) =
234234
calculates the the total number of integers or dates of an integer or date
235235
valued interval. For example, `duration(0..1)` is 2, while `width(0..1)` is 1.
236236
"""
237-
duration(A::TypedEndpointsInterval{:closed,:closed,T}) where {T<:Integer} = max(0, Int(A.right - A.left) + 1)
238-
duration(A::TypedEndpointsInterval{:closed,:closed,Date}) = max(0, Dates.days(A.right - A.left) + 1)
237+
function duration(A::TypedEndpointsInterval{:closed,:closed,T}) where {T<:Integer}
238+
# TODO: Remove this method in the next breaking release
239+
Base.depwarn("`duration` will be removed in the next breaking release because it is ill-defined concept. " *
240+
"If you need 3 from 2..4, replace duration(2..4) with width(2..4)+1", :duration)
241+
max(0, Int(A.right - A.left) + 1)
242+
end
243+
function duration(A::TypedEndpointsInterval{:closed,:closed,Date})
244+
# TODO: Remove this method in the next breaking release
245+
Base.depwarn("`duration` will be removed in the next breaking release because it is ill-defined concept. " *
246+
"If you need 961 from A=Date(2018,08,08)..Date(2021,03,25), replace duration(A) with Dates.days(width(A))+1", :duration)
247+
max(0, Dates.days(A.right - A.left) + 1)
248+
end
239249

240250
include("interval.jl")
241251

0 commit comments

Comments
 (0)