Skip to content

Commit

Permalink
Extend contains from Base when defined (#41)
Browse files Browse the repository at this point in the history
This function is "new" in Julia 1.5. This change will avoid breaking the
package on Julia nightly.
  • Loading branch information
ararslan authored Apr 17, 2020
1 parent fbc243a commit a460a38
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/timespans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ Base.last(span::TimeSpan) = span.last
##### `AbstractTimeSpan` Utilities
#####

# Extend the Base function when defined
if isdefined(Base, :contains) # VERSION >= v"1.5.0-DEV.639"
import Base: contains
end

"""
contains(a, b)
contains(a::AbstractTimeSpan, b::AbstractTimeSpan)
Return `true` if the timespan `b` lies entirely within the timespan `a`, return `false` otherwise.
"""
function contains(a, b)
a, b = TimeSpan(a), TimeSpan(b)
function contains(a::AbstractTimeSpan, b::AbstractTimeSpan)
return first(a) <= first(b) && last(a) >= last(b)
end

Expand Down

0 comments on commit a460a38

Please sign in to comment.