|
1 | | -const TIME_ZONE_CACHE = Dict{String,Tuple{TimeZone,Class}}() |
| 1 | +const TIME_ZONE_CACHE = Dict{Name,Tuple{TimeZone,Class}}() |
2 | 2 |
|
3 | 3 | """ |
4 | 4 | TimeZone(str::AbstractString) -> TimeZone |
@@ -41,11 +41,15 @@ US/Pacific (UTC-8/UTC-7) |
41 | 41 | TimeZone(::AbstractString, ::Class) |
42 | 42 |
|
43 | 43 | function TimeZone(str::AbstractString, mask::Class=Class(:DEFAULT)) |
| 44 | + return TimeZone(convert(Name, str), mask) |
| 45 | +end |
| 46 | + |
| 47 | +function TimeZone(name::Name, mask::Class=Class(:DEFAULT)) |
| 48 | + str = string(name) |
44 | 49 | # Note: If the class `mask` does not match the time zone we'll still load the |
45 | 50 | # information into the cache to ensure the result is consistent. |
46 | | - tz, class = get!(TIME_ZONE_CACHE, str) do |
47 | | - tz_path = joinpath(TZData.COMPILED_DIR, split(str, "/")...) |
48 | | - |
| 51 | + tz, class = get!(TIME_ZONE_CACHE, name) do |
| 52 | + tz_path = joinpath(TZData.COMPILED_DIR, name_parts(name)...) |
49 | 53 | if isfile(tz_path) |
50 | 54 | open(deserialize, tz_path, "r") |
51 | 55 | elseif occursin(FIXED_TIME_ZONE_REGEX, str) |
|
91 | 95 |
|
92 | 96 | Check whether a string is a valid for constructing a `TimeZone` with the provided `mask`. |
93 | 97 | """ |
94 | | -function istimezone(str::AbstractString, mask::Class=Class(:DEFAULT)) |
| 98 | +function istimezone(str::Union{AbstractString, Name}, mask::Class=Class(:DEFAULT)) |
95 | 99 | # Start by performing quick FIXED class test |
96 | | - if mask & Class(:FIXED) != Class(:NONE) && occursin(FIXED_TIME_ZONE_REGEX, str) |
| 100 | + if mask & Class(:FIXED) != Class(:NONE) && occursin(FIXED_TIME_ZONE_REGEX, string(str)) |
97 | 101 | return true |
98 | 102 | end |
| 103 | + name = convert(Name, str) |
99 | 104 |
|
100 | 105 | # Perform more expensive checks against pre-compiled time zones |
101 | 106 | tz, class = get(TIME_ZONE_CACHE, str) do |
102 | | - tz_path = joinpath(TZData.COMPILED_DIR, split(str, "/")...) |
| 107 | + tz_path = joinpath(TZData.COMPILED_DIR, name_parts(name)...) |
103 | 108 |
|
104 | 109 | if isfile(tz_path) |
105 | 110 | # Cache the data since we're already performing the deserialization |
106 | | - TIME_ZONE_CACHE[str] = open(deserialize, tz_path, "r") |
| 111 | + TIME_ZONE_CACHE[name] = open(deserialize, tz_path, "r") |
107 | 112 | else |
108 | 113 | nothing, Class(:NONE) |
109 | 114 | end |
|
0 commit comments