Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/TimeZones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Dates
using Printf
using Serialization
using RecipesBase: RecipesBase, @recipe
using ShortStrings: ShortString15
using Unicode

import Dates: TimeZone, UTC
Expand Down
8 changes: 6 additions & 2 deletions src/types/fixedtimezone.jl
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wish the 32-bit problem was properly fixed... if this is what we need to do then let's be as clear about it as we can.

Suggested change
const FixedTimeZoneName = Int === Int64 ? ShortString15 : String
const FixedTimeZoneName = Sys.WORD_SIZE == 64 ? ShortString15 : String

Copy link
Contributor Author

@oxinabox oxinabox May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now fixed. So this PR needs updating


const FIXED_TIME_ZONE_REGEX = r"""
^(?|
Z
Expand Down Expand Up @@ -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
Copy link
Member

@omus omus Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once ShortStrings.jl is fixed this type alias won't survive. May as well try to indicate what it truly is.

Suggested change
name::FixedTimeZoneName
name::_ShortString15

offset::UTCOffset
end

Expand Down Expand Up @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see an error before changing this? I'll note SubString{String} also works here so we don't always need to call String

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it errors before

Iirc I looked in the docs for regex and it explicitly said it only worked on String. Which is a weird thing for Julia docs to say.
And also weird that it doesn't convert abstract strings to strings for it.

m === nothing && throw(ArgumentError("Unrecognized time zone: $s"))

coefficient = m[:sign] == "-" ? -1 : 1
Expand Down
10 changes: 10 additions & 0 deletions test/types/fixedtimezone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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