From 7ba4d857401eca4666baeb6741c5da8ff6834fc1 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Mon, 12 Apr 2021 19:02:11 +0100 Subject: [PATCH 1/2] make FixedTimeZones be isbits by using ShortStrings Tweak comment tweak comment do use split with short strings Julia needs brakets for function application --- Project.toml | 2 ++ src/TimeZones.jl | 1 + src/types/fixedtimezone.jl | 8 ++++++-- test/types/fixedtimezone.jl | 10 ++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index aabb70883..5cd54a2d0 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.6" julia = "1" [extras] diff --git a/src/TimeZones.jl b/src/TimeZones.jl index 754cecf58..17c1d9ece 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 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/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 From d2fdec9b6e9bcf05e3143b9a1a29f39805cdaaa6 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Wed, 14 Apr 2021 12:37:34 +0100 Subject: [PATCH 2/2] use ShortString for VariableTimeZone name --- Project.toml | 2 +- src/TimeZones.jl | 2 +- src/types/variabletimezone.jl | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 5cd54a2d0..715d978b9 100644 --- a/Project.toml +++ b/Project.toml @@ -18,7 +18,7 @@ Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" EzXML = "0.9.1, 1" Mocking = "0.7" RecipesBase = "0.7, 0.8, 1" -ShortStrings = "0.3.6" +ShortStrings = "0.3.7" julia = "1" [extras] diff --git a/src/TimeZones.jl b/src/TimeZones.jl index 17c1d9ece..57c60e20f 100644 --- a/src/TimeZones.jl +++ b/src/TimeZones.jl @@ -4,7 +4,7 @@ using Dates using Printf using Serialization using RecipesBase: RecipesBase, @recipe -using ShortStrings: ShortString15 +using ShortStrings: ShortString15, ShortString63 using Unicode import Dates: TimeZone, UTC 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}