diff --git a/stdlib/Dates/src/types.jl b/stdlib/Dates/src/types.jl index 783e4f9b53b7f..c0202bd9171b3 100644 --- a/stdlib/Dates/src/types.jl +++ b/stdlib/Dates/src/types.jl @@ -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) diff --git a/stdlib/Dates/test/types.jl b/stdlib/Dates/test/types.jl index 1cda5b51e6101..8e256b9ef7576 100644 --- a/stdlib/Dates/test/types.jl +++ b/stdlib/Dates/test/types.jl @@ -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