From cfc2c13c70d1c46772bc1a7367ccd1e6552990a9 Mon Sep 17 00:00:00 2001 From: Nicole Epp Date: Fri, 16 Oct 2020 13:48:10 -0500 Subject: [PATCH] Add explicit error for :anchor on kwarg for non Anchored Intervals --- src/interval.jl | 4 ++++ test/interval.jl | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/interval.jl b/src/interval.jl index f3cbefb5..198d0847 100644 --- a/src/interval.jl +++ b/src/interval.jl @@ -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} diff --git a/test/interval.jl b/test/interval.jl index a5131f75..4c07449b 100644 --- a/test/interval.jl +++ b/test/interval.jl @@ -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)) @@ -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)) @@ -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))