Skip to content

Commit 1c4527a

Browse files
committed
use ShortStrings directly for keys of FixedTimeZones
2 parents f07d246 + 9e7b073 commit 1c4527a

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
1818
EzXML = "0.9.1, 1"
1919
Mocking = "0.7"
2020
RecipesBase = "0.7, 0.8, 1"
21-
ShortStrings = "0.3.5"
21+
ShortStrings = "0.3.6"
2222
julia = "1"
2323

2424
[extras]

dev/ShortStrings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 65ca2364af105fc2647befe0b73ca3ecdd8c9f7a

src/TimeZones.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Printf
55
using ShortStrings
66
using Serialization
77
using RecipesBase: RecipesBase, @recipe
8+
using ShortStrings: ShortString15
89
using Unicode
910

1011
import Dates: TimeZone, UTC

src/types/fixedtimezone.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Ideally would always use ShortString15, but it's `hash` is broken on 32-bit systems.
2+
# https://github.com/JuliaString/MurmurHash3.jl/issues/12
3+
const FixedTimeZoneName = Int === Int64 ? ShortString15 : String
4+
15
const FIXED_TIME_ZONE_REGEX = r"""
26
^(?|
37
Z
@@ -30,7 +34,7 @@ const FIXED_TIME_ZONE_REGEX = r"""
3034
A `TimeZone` with a constant offset for all of time.
3135
"""
3236
struct FixedTimeZone <: TimeZone
33-
name::Name
37+
name::FixedTimeZoneName
3438
offset::UTCOffset
3539
end
3640

@@ -72,7 +76,7 @@ UTC+15:45:21
7276
function FixedTimeZone(s::AbstractString)
7377
s == "Z" && return UTC_ZERO
7478

75-
m = match(FIXED_TIME_ZONE_REGEX, s)
79+
m = match(FIXED_TIME_ZONE_REGEX, String(s))
7680
m === nothing && throw(ArgumentError("Unrecognized time zone: $s"))
7781

7882
coefficient = m[:sign] == "-" ? -1 : 1

test/types/fixedtimezone.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@
4141
fixed_tz = FixedTimeZone("UTC")
4242
@test size(fixed_tz .== fixed_tz) == ()
4343
end
44+
45+
@testset "isbits" begin
46+
# We are not using ShortStrings on 32-bit due to hash being broken on 32-bit.
47+
# See https://github.com/JuliaString/MurmurHash3.jl/issues/12
48+
if Int === Int64
49+
@test isbits(FixedTimeZone("0123"))
50+
else
51+
@test_broken isbits(FixedTimeZone("0123"))
52+
end
53+
end
4454
end

0 commit comments

Comments
 (0)