Skip to content

Commit a218132

Browse files
oxinaboxiamed2omus
authored andcommitted
Simplify hash of VariableTimeZone (JuliaTime#281)
Co-authored-by: Eric Davies <iamed2@gmail.com> Co-authored-by: Curtis Vogt <curtis.vogt@gmail.com>
1 parent f4bb253 commit a218132

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/types/variabletimezone.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ function Base.isequal(a::VariableTimeZone, b::VariableTimeZone)
3939
end
4040

4141
function Base.hash(tz::VariableTimeZone, h::UInt)
42+
h = hash(:timezone, h)
4243
h = hash(tz.name, h)
43-
h = hash(tz.transitions, h)
44-
h = hash(tz.cutoff, h)
4544
return h
4645
end

test/types/variabletimezone.jl

+13-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@
4444
@test a == b
4545
@test a !== b
4646
@test !isequal(a, b)
47-
@test hash(a) != hash(b)
47+
@test hash(a) == hash(b)
48+
end
49+
50+
@testset "hash using name" begin
51+
a = first(compile("Europe/Warsaw", tzdata["europe"]))
52+
b = VariableTimeZone("Europe/Warsaw", a.transitions[1:1], nothing)
53+
54+
# To be fast the `hash` function only uses the name. However, when a hash collision
55+
# does occur it should be disambiguated by the `isequal` check which also considers
56+
# the transition and the cutoff.
57+
@test hash(a) == hash(b)
58+
@test !isequal(a, b)
59+
@test length(keys(Dict(a => :a, b => :b))) == 2 # Time zones use different keys
4860
end
4961
end

0 commit comments

Comments
 (0)