From 8c6480ba180ea42d9b5753d50bdd1891958a61cd Mon Sep 17 00:00:00 2001 From: Pontus Stenetorp Date: Fri, 18 May 2018 19:18:57 -0400 Subject: [PATCH] FixedPeriod and period comparison to return false As per issue #27076. --- stdlib/Dates/src/periods.jl | 6 +++--- stdlib/Dates/test/periods.jl | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/stdlib/Dates/src/periods.jl b/stdlib/Dates/src/periods.jl index e37d227b97f56..71f1eb4f9ae8c 100644 --- a/stdlib/Dates/src/periods.jl +++ b/stdlib/Dates/src/periods.jl @@ -442,9 +442,9 @@ end Base.convert(::Type{Year}, x::Month) = Year(divexact(value(x), 12)) Base.promote_rule(::Type{Year}, ::Type{Month}) = Month -# disallow comparing fixed to other periods -(==)(x::FixedPeriod, y::OtherPeriod) = throw(MethodError(==, (x, y))) -(==)(x::OtherPeriod, y::FixedPeriod) = throw(MethodError(==, (x, y))) +# fixed is not comparable to other periods, as per discussion in issue #21378 +(==)(x::FixedPeriod, y::OtherPeriod) = false +(==)(x::OtherPeriod, y::FixedPeriod) = false const fixedperiod_seed = UInt === UInt64 ? 0x5b7fc751bba97516 : 0xeae0fdcb const otherperiod_seed = UInt === UInt64 ? 0xe1837356ff2d2ac9 : 0x170d1b00 diff --git a/stdlib/Dates/test/periods.jl b/stdlib/Dates/test/periods.jl index 27f3c1bd8e553..aa312a123625c 100644 --- a/stdlib/Dates/test/periods.jl +++ b/stdlib/Dates/test/periods.jl @@ -247,8 +247,10 @@ end @test Dates.Millisecond(1) == Dates.Millisecond(1) @test_throws MethodError Dates.Year(1) < Dates.Millisecond(1) @test_throws MethodError Dates.Millisecond(1) < Dates.Year(1) - @test_throws MethodError Dates.Year(1) == Dates.Millisecond(1) - @test_throws MethodError Dates.Millisecond(1) == Dates.Year(1) + + # issue #27076 + @test Dates.Year(1) != Dates.Millisecond(1) + @test Dates.Millisecond(1) != Dates.Year(1) end struct Beat <: Dates.Period