diff --git a/deps/build.jl b/deps/build.jl index 0df41a4e6..77adf1cd5 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,5 +1,13 @@ -import TimeZones: TZDATA_DIR, COMPILED_DIR, fixed_timezones -import TimeZones.Olson: REGIONS, compile +import TimeZones: TZDATA_DIR, COMPILED_DIR +import TimeZones.Olson: compile + +# See "ftp://ftp.iana.org/tz/data/Makefile" PRIMARY_YDATA for listing of +# regions to include. YDATA includes historical zones which we'll ignore. +const REGIONS = ( + "africa", "antarctica", "asia", "australasia", + "europe", "northamerica", "southamerica", + # "pacificnew", "etcetera", "backward", # Historical zones +) isdir(TZDATA_DIR) || mkdir(TZDATA_DIR) isdir(COMPILED_DIR) || mkdir(COMPILED_DIR) @@ -42,16 +50,4 @@ for file in readdir(COMPILED_DIR) end compile(TZDATA_DIR, COMPILED_DIR) -info("Adding additional FixedTimeZones") -for (name, tz) in fixed_timezones() - parts = split(name, "/") - tz_dir, tz_file = joinpath(COMPILED_DIR, parts[1:end-1]...), parts[end] - - isdir(tz_dir) || mkpath(tz_dir) - - open(joinpath(tz_dir, tz_file), "w") do fp - serialize(fp, tz) - end -end - info("Successfully processed TimeZone data") diff --git a/deps/tzdata/utc b/deps/tzdata/utc new file mode 100644 index 000000000..fcaf88efc --- /dev/null +++ b/deps/tzdata/utc @@ -0,0 +1,5 @@ +# Zones specifically for TimeZones.jl + +# Zone NAME GMTOFF RULES FORMAT [UNTIL] +Zone UTC 0 - UTC +Zone GMT 0 - GMT diff --git a/src/TimeZones.jl b/src/TimeZones.jl index 65a305360..87201bee7 100644 --- a/src/TimeZones.jl +++ b/src/TimeZones.jl @@ -29,7 +29,6 @@ include("timezones/io.jl") include("timezones/adjusters.jl") include("timezones/Olson.jl") include("timezones/conversions.jl") -include("timezones/fixed.jl") function TimeZone(name::AbstractString) tz_path = joinpath(COMPILED_DIR, split(name, "/")...) diff --git a/src/timezones/Olson.jl b/src/timezones/Olson.jl index 8c16491d6..47aae8d9f 100644 --- a/src/timezones/Olson.jl +++ b/src/timezones/Olson.jl @@ -6,11 +6,6 @@ import ..TimeZones: TZDATA_DIR, COMPILED_DIR, ZERO, MIN_GMT_OFFSET, MAX_GMT_OFFS MIN_SAVE, MAX_SAVE, ABS_DIFF_OFFSET, Time, toseconds import ..TimeZones: TimeZone, FixedTimeZone, VariableTimeZone, Transition, Time -const REGIONS = ( - "africa", "antarctica", "asia", "australasia", - "europe", "northamerica", "southamerica", -) - # Zone type maps to an Olson Timezone database entity type Zone gmtoffset::Time @@ -509,8 +504,8 @@ end function load(tzdata_dir::AbstractString=TZDATA_DIR) timezones = Dict{AbstractString,TimeZone}() - for region in REGIONS - zones, rules = tzparse(joinpath(tzdata_dir, region)) + for filename in readdir(tzdata_dir) + zones, rules = tzparse(joinpath(tzdata_dir, filename)) merge!(timezones, resolve(zones, rules)) end return timezones diff --git a/src/timezones/fixed.jl b/src/timezones/fixed.jl deleted file mode 100644 index 05756b152..000000000 --- a/src/timezones/fixed.jl +++ /dev/null @@ -1,19 +0,0 @@ -function fixed_timezones() - fixedzones = Dict{AbstractString, TimeZone}() - # UTC equivalent times - utc = FixedTimeZone("UTC", 0) - for name in ("UTC", "Universal", "Zulu", "Etc/UTC", "Etc/Universal", "Etc/Zulu") - fixedzones[name] = utc - end - # GMT equivalent times - gmt = FixedTimeZone("GMT", 0) - for name in ("GMT", "Etc/GMT", "Etc/GMT+0", "Etc/GMT-0") - fixedzones[name] = gmt - end - # GMT-14 to GMT-1 and GMT+1 to GMT+12 - for i in [-14:-1; 1:12] - abbr = @sprintf("GMT%+d", i) - fixedzones["Etc/$abbr"] = FixedTimeZone(abbr, -i * 3600) - end - return fixedzones -end diff --git a/test/runtests.jl b/test/runtests.jl index 5022bf9e7..5aca28f92 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,5 +23,4 @@ include("timezones/arithmetic.jl") include("timezones/io.jl") include("timezones/adjusters.jl") include("timezones/conversions.jl") -include("timezones/fixed.jl") include("timezone_names.jl") diff --git a/test/timezone_names.jl b/test/timezone_names.jl index 5bc7cf958..83a4bc9c6 100644 --- a/test/timezone_names.jl +++ b/test/timezone_names.jl @@ -5,3 +5,8 @@ names = timezone_names() @test length(names) >= 429 @test isa(names, Array{AbstractString}) @test issorted(names) + +# Make sure that extra timezones exist from "deps/tzdata/utc". +# If tests fail try rebuilding the package: Pkg.build("TimeZones") +@test "UTC" in names +@test "GMT" in names diff --git a/test/timezones/fixed.jl b/test/timezones/fixed.jl deleted file mode 100644 index f45eaa772..000000000 --- a/test/timezones/fixed.jl +++ /dev/null @@ -1,18 +0,0 @@ -fixedzones = TimeZones.fixed_timezones() - -for name in ("UTC", "Universal", "Zulu", "Etc/UTC", "Etc/Universal", "Etc/Zulu") - tz = fixedzones[name] - @test tz == FixedTimeZone("UTC", 0) -end - -for name in ("GMT", "Etc/GMT", "Etc/GMT+0", "Etc/GMT-0") - tz = fixedzones[name] - @test tz == FixedTimeZone("GMT", 0) -end - -for i in [-14:-1; 1:12] - abbr = @sprintf("GMT%+d", i) - name = "Etc/$abbr" - tz = fixedzones[name] - @test tz == FixedTimeZone(abbr, -i * 3600) -end