Skip to content

Commit

Permalink
Add explicit error for :anchor on kwarg for non Anchored Intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoleepp committed Oct 16, 2020
1 parent a9e2927 commit cfc2c13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ for f in (:floor, :ceil, :round)
end
end

function _round(f::RoundingFunctionTypes, interval::Interval, on::Val{:anchor}, args...)
throw(ArgumentError(":anchor is only usable with an AnchoredInterval."))
end

function _round(
f::RoundingFunctionTypes, interval::Interval{T,L,R}, on::Val{:left}, args...
) where {T, L <: Bounded, R <: Bounded}
Expand Down
6 changes: 3 additions & 3 deletions test/interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@
@test floor(Interval(0.5, 1.5); on=:right) == Interval(0.0, 1.0)

# :anchor is only usable with AnchoredIntervals
@test_throws MethodError floor(Interval(0.0, 1.0); on=:anchor)
@test_throws ArgumentError floor(Interval(0.0, 1.0); on=:anchor)

# Test supplying a period to floor to
interval = Interval(DateTime(2011, 2, 1, 6), DateTime(2011, 2, 2, 18))
Expand Down Expand Up @@ -951,7 +951,7 @@
@test ceil(Interval(0.5, 1.5); on=:right) == Interval(1.0, 2.0)

# :anchor is only usable with AnchoredIntervals
@test_throws MethodError ceil(Interval(0.0, 1.0); on=:anchor)
@test_throws ArgumentError ceil(Interval(0.0, 1.0); on=:anchor)

# Test supplying a period to ceil to
interval = Interval(DateTime(2011, 2, 1, 6), DateTime(2011, 2, 2, 18))
Expand Down Expand Up @@ -996,7 +996,7 @@
@test round(Interval(0.5, 1.5); on=:right) == Interval(1.0, 2.0)

# :anchor is only usable with AnchoredIntervals
@test_throws MethodError round(Interval(0.0, 1.0); on=:anchor)
@test_throws ArgumentError round(Interval(0.0, 1.0); on=:anchor)

# Test supplying a period to round to
interval = Interval(DateTime(2011, 2, 1, 6), DateTime(2011, 2, 2, 18))
Expand Down

0 comments on commit cfc2c13

Please sign in to comment.