Skip to content

Commit 7ba4d85

Browse files
committed
make FixedTimeZones be isbits by using ShortStrings
Tweak comment tweak comment do use split with short strings Julia needs brakets for function application
1 parent faa208e commit 7ba4d85

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1111
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1212
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1313
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
14+
ShortStrings = "63221d1c-8677-4ff0-9126-0ff0817b4975"
1415
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
1516

1617
[compat]
1718
EzXML = "0.9.1, 1"
1819
Mocking = "0.7"
1920
RecipesBase = "0.7, 0.8, 1"
21+
ShortStrings = "0.3.6"
2022
julia = "1"
2123

2224
[extras]

src/TimeZones.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Dates
44
using Printf
55
using Serialization
66
using RecipesBase: RecipesBase, @recipe
7+
using ShortStrings: ShortString15
78
using Unicode
89

910
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::String
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)