Skip to content

Commit

Permalink
Fix hashing of Dates.Time. Fixes #29480 (#29742)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1db6047)
  • Loading branch information
JeffBezanson authored and KristofferC committed Oct 29, 2018
1 parent ebbaf5d commit 116b091
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stdlib/Dates/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ function ==(a::Time, b::Time)
microsecond(a) == microsecond(b) && nanosecond(a) == nanosecond(b)
end
(==)(x::TimeType, y::TimeType) = (===)(promote(x, y)...)
Base.hash(x::Time, h::UInt) =
hash(hour(x), hash(minute(x), hash(second(x),
hash(millisecond(x), hash(microsecond(x), hash(nanosecond(x), h))))))

import Base: sleep, Timer, timedwait
sleep(time::Period) = sleep(toms(time) / 1000)
Expand Down
4 changes: 4 additions & 0 deletions stdlib/Dates/test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ c = Dates.Time(0)
@test isfinite(Dates.Date)
@test isfinite(Dates.DateTime)
@test isfinite(Dates.Time)
@test c == c
@test c == (c + Dates.Hour(24))
@test hash(c) == hash(c + Dates.Hour(24))
@test hash(c + Dates.Nanosecond(10)) == hash(c + Dates.Hour(24) + Dates.Nanosecond(10))
end
@testset "Date-DateTime conversion/promotion" begin
global a, b, c, d
Expand Down

0 comments on commit 116b091

Please sign in to comment.