Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] FixedPeriod and period comparison to return false #27165

Merged
merged 1 commit into from May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/Dates/src/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions stdlib/Dates/test/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down