diff --git a/Project.toml b/Project.toml index aabb70883..715d978b9 100644 --- a/Project.toml +++ b/Project.toml @@ -11,12 +11,14 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" +ShortStrings = "63221d1c-8677-4ff0-9126-0ff0817b4975" Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [compat] EzXML = "0.9.1, 1" Mocking = "0.7" RecipesBase = "0.7, 0.8, 1" +ShortStrings = "0.3.7" julia = "1" [extras] diff --git a/src/TimeZones.jl b/src/TimeZones.jl index 754cecf58..57c60e20f 100644 --- a/src/TimeZones.jl +++ b/src/TimeZones.jl @@ -4,6 +4,7 @@ using Dates using Printf using Serialization using RecipesBase: RecipesBase, @recipe +using ShortStrings: ShortString15, ShortString63 using Unicode import Dates: TimeZone, UTC diff --git a/src/types/fixedtimezone.jl b/src/types/fixedtimezone.jl index 1d349ca07..a6bd2a181 100644 --- a/src/types/fixedtimezone.jl +++ b/src/types/fixedtimezone.jl @@ -1,3 +1,7 @@ +# Ideally would always use ShortString15, but it's `hash` is broken on 32-bit systems. +# https://github.com/JuliaString/MurmurHash3.jl/issues/12 +const FixedTimeZoneName = Int === Int64 ? ShortString15 : String + const FIXED_TIME_ZONE_REGEX = r""" ^(?| Z @@ -30,7 +34,7 @@ const FIXED_TIME_ZONE_REGEX = r""" A `TimeZone` with a constant offset for all of time. """ struct FixedTimeZone <: TimeZone - name::String + name::FixedTimeZoneName offset::UTCOffset end @@ -72,7 +76,7 @@ UTC+15:45:21 function FixedTimeZone(s::AbstractString) s == "Z" && return UTC_ZERO - m = match(FIXED_TIME_ZONE_REGEX, s) + m = match(FIXED_TIME_ZONE_REGEX, String(s)) m === nothing && throw(ArgumentError("Unrecognized time zone: $s")) coefficient = m[:sign] == "-" ? -1 : 1 diff --git a/src/types/variabletimezone.jl b/src/types/variabletimezone.jl index 35b2b89b6..eedf8230e 100644 --- a/src/types/variabletimezone.jl +++ b/src/types/variabletimezone.jl @@ -5,13 +5,17 @@ end Base.isless(a::Transition, b::Transition) = isless(a.utc_datetime, b.utc_datetime) +# Ideally would always use ShortString63, but it's `hash` is broken on 32-bit systems. +# https://github.com/JuliaString/MurmurHash3.jl/issues/12 +const VariableZoneName = Int === Int64 ? ShortString63 : String + """ VariableTimeZone A `TimeZone` with an offset that changes over time. """ struct VariableTimeZone <: TimeZone - name::String + name::VariableZoneName transitions::Vector{Transition} cutoff::Union{DateTime,Nothing} diff --git a/test/types/fixedtimezone.jl b/test/types/fixedtimezone.jl index 94cae0ab4..774f67283 100644 --- a/test/types/fixedtimezone.jl +++ b/test/types/fixedtimezone.jl @@ -41,4 +41,14 @@ fixed_tz = FixedTimeZone("UTC") @test size(fixed_tz .== fixed_tz) == () end + + @testset "isbits" begin + # We are not using ShortStrings on 32-bit due to hash being broken on 32-bit. + # See https://github.com/JuliaString/MurmurHash3.jl/issues/12 + if Int === Int64 + @test isbits(FixedTimeZone("0123")) + else + @test_broken isbits(FixedTimeZone("0123")) + end + end end