@@ -29,9 +29,20 @@ const FIXED_TIME_ZONE_REGEX = r"""
2929
3030A `TimeZone` with a constant offset for all of time.
3131"""
32- struct FixedTimeZone <: TimeZone
32+ mutable struct FixedTimeZone <: TimeZone
3333 name:: String
3434 offset:: UTCOffset
35+ index:: Int
36+
37+ function FixedTimeZone (name:: String , utc_offset:: UTCOffset )
38+ tz = new (name, utc_offset)
39+ tz. index = add! (_TIME_ZONES, tz)
40+ return tz
41+ end
42+ end
43+
44+ function FixedTimeZone (name:: AbstractString , utc_offset:: UTCOffset )
45+ FixedTimeZone (convert (String, name), utc_offset)
3546end
3647
3748"""
@@ -48,6 +59,21 @@ function FixedTimeZone(name::AbstractString, utc_offset::Second, dst_offset::Sec
4859 FixedTimeZone (name, UTCOffset (utc_offset, dst_offset))
4960end
5061
62+ # Overload serialization to ensure that `FixedTimeZone` serialization doesn't transfer
63+ # state information which is specific to the current Julia process.
64+ function Serialization. serialize (s:: AbstractSerializer , tz:: FixedTimeZone )
65+ Serialization. serialize_type (s, typeof (tz))
66+ serialize (s, tz. name)
67+ serialize (s, tz. offset)
68+ end
69+
70+ function Serialization. deserialize (s:: AbstractSerializer , :: Type{FixedTimeZone} )
71+ name = deserialize (s)
72+ offset = deserialize (s)
73+
74+ return FixedTimeZone (name, offset)
75+ end
76+
5177# https://en.wikipedia.org/wiki/ISO_8601#Coordinated_Universal_Time_(UTC)
5278const UTC_ZERO = FixedTimeZone (" Z" , 0 )
5379
95121
96122name (tz:: FixedTimeZone ) = tz. name
97123rename (tz:: FixedTimeZone , name:: AbstractString ) = FixedTimeZone (name, tz. offset)
124+
125+ function Base.:(== )(a:: FixedTimeZone , b:: FixedTimeZone )
126+ return a. name == b. name && a. offset == b. offset
127+ end
128+
129+ function Base. hash (tz:: FixedTimeZone , h:: UInt )
130+ h = hash (:timezone , h)
131+ h = hash (tz. name, h)
132+ return h
133+ end
134+
135+ function Base. isequal (a:: FixedTimeZone , b:: FixedTimeZone )
136+ return isequal (a. name, b. name) && isequal (a. offset, b. offset)
137+ end
0 commit comments