From 8ddf3339f3365e9c4dd2fbf3520136b782161d5f Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 24 Oct 2017 14:18:51 -0500 Subject: [PATCH 1/7] Update readstring(x) to read(x, String) --- REQUIRE | 4 ++-- src/local.jl | 8 ++++---- src/tzdata/version.jl | 4 ++-- test/local_mocking.jl | 8 ++++---- test/runtests.jl | 7 +++---- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/REQUIRE b/REQUIRE index 6ab2d2aab..7c7780836 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ julia 0.6 -Compat 0.27 -Mocking 0.2 +Compat 0.30 +Mocking 0.4 @windows LightXML 0.2 diff --git a/src/local.jl b/src/local.jl index 931141c08..c2ee79af8 100644 --- a/src/local.jl +++ b/src/local.jl @@ -1,6 +1,6 @@ # Determine the local system's time zone # Based upon Python's tzlocal https://pypi.python.org/pypi/tzlocal -import Compat: @static, Sys, readstring +import Compat: @static, Sys, read using Mocking if Sys.iswindows() @@ -14,7 +14,7 @@ Returns a `TimeZone` object that is equivalent to the system's current time zone """ function localzone() @static if Sys.isapple() - name = @mock readstring(`systemsetup -gettimezone`) # Appears to only work as root + name = @mock read(`systemsetup -gettimezone`, String) # Appears to only work as root if contains(name, "Time Zone: ") name = strip(replace(name, "Time Zone: ", "")) else @@ -69,7 +69,7 @@ function localzone() filename = "/etc/timezone" if @mock isfile(filename) @mock open(filename) do file - name = readstring(file) + name = read(file, String) # Get rid of host definitions and comments: name = strip(replace(name, r"#.*", "")) @@ -123,7 +123,7 @@ function localzone() end elseif Sys.iswindows() # Windows powershell should be available on Windows 7 and above - win_name = strip(@mock readstring(`powershell -Command "[TimeZoneInfo]::Local.Id"`)) + win_name = strip(@mock read(`powershell -Command "[TimeZoneInfo]::Local.Id"`, String)) if haskey(WINDOWS_TRANSLATION, win_name) posix_name = WINDOWS_TRANSLATION[win_name] diff --git a/src/tzdata/version.jl b/src/tzdata/version.jl index 2cb77a22e..7d249056e 100644 --- a/src/tzdata/version.jl +++ b/src/tzdata/version.jl @@ -1,5 +1,5 @@ import ...TimeZones: DEPS_DIR, ARCHIVE_DIR -import Compat: readstring +import Compat: read # Note: A tz code or data version consists of a year and letter while a release consists of # a pair of tz code and data versions. In recent releases the tz code and data use the same @@ -94,7 +94,7 @@ end function active_version() !isfile(ACTIVE_VERSION_FILE) && error("No active tzdata version") - readstring(ACTIVE_VERSION_FILE) + read(ACTIVE_VERSION_FILE, String) end function active_archive() diff --git a/test/local_mocking.jl b/test/local_mocking.jl index b7b7dac33..647e5ef9a 100644 --- a/test/local_mocking.jl +++ b/test/local_mocking.jl @@ -1,7 +1,7 @@ import TimeZones: TimeZone, localzone import Mocking: @patch, apply import Base: AbstractCmd -import Compat: Sys, readstring +import Compat: Sys, read # For mocking make sure we are actually changing the time zone name = string(localzone()) == "Europe/Warsaw" ? "Pacific/Apia" : "Europe/Warsaw" @@ -13,14 +13,14 @@ timezone = TimeZone(name) if Sys.isapple() # Determine time zone via systemsetup. - patch = @patch readstring(cmd::AbstractCmd) = "Time Zone: " * name * "\n" + patch = @patch read(cmd::AbstractCmd, ::Type{String}) = "Time Zone: " * name * "\n" apply(patch) do @test localzone() == timezone end # Determine time zone from /etc/localtime. patches = [ - @patch readstring(cmd::AbstractCmd) = "" + @patch read(cmd::AbstractCmd, ::Type{String}) = "" @patch readlink(filename::AbstractString) = "/usr/share/zoneinfo/$name" ] apply(patches) do @@ -28,7 +28,7 @@ if Sys.isapple() end elseif Sys.iswindows() - patch = @patch readstring(cmd::AbstractCmd) = "$win_name\r\n" + patch = @patch read(cmd::AbstractCmd, ::Type{String}) = "$win_name\r\n" apply(patch) do @test localzone() == timezone end diff --git a/test/runtests.jl b/test/runtests.jl index 54f5cb311..6bba9b573 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,7 @@ using Mocking -opts = Base.JLOptions() -use_compilecache = !isdefined(opts, :use_compilecache) || Bool(opts.use_compilecache) -if use_compilecache +precompile_enabled = Mocking.is_precompile_enabled() +if precompile_enabled warn("Julia not started with `--compilecache=no`. Disabling tests that require Mocking") else Mocking.enable() @@ -57,7 +56,7 @@ include("adjusters.jl") include("conversions.jl") include("ranges.jl") include("local.jl") -!use_compilecache && include("local_mocking.jl") +!precompile_enabled && include("local_mocking.jl") include("discovery.jl") VERSION >= v"0.5.0-dev+5244" && include("rounding.jl") include("TimeZones.jl") From 06490b1359f3362bdd1358648004e19055eccc7a Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 24 Oct 2017 14:22:38 -0500 Subject: [PATCH 2/7] Update missed is_windows calls --- src/TimeZones.jl | 6 +++--- test/runtests.jl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TimeZones.jl b/src/TimeZones.jl index 34aa5684a..7c5b30e8d 100644 --- a/src/TimeZones.jl +++ b/src/TimeZones.jl @@ -5,7 +5,7 @@ module TimeZones using Base.Dates import Base.Dates: TimeZone, AbstractTime import Base: @deprecate_binding -import Compat: is_windows +import Compat: Sys export TimeZone, @tz_str, FixedTimeZone, VariableTimeZone, ZonedDateTime, DateTime, TimeError, AmbiguousTimeError, NonExistentTimeError, UnhandledTimeError, @@ -105,7 +105,7 @@ flag is used to re-download tzdata archives. function build(version::AbstractString="latest", regions=REGIONS; force::Bool=false) TimeZones.TZData.build(version, regions) - if is_windows() + if Sys.iswindows() TimeZones.WindowsTimeZoneIDs.build(force=force) end @@ -117,7 +117,7 @@ include("utcoffset.jl") include("types.jl") include("exceptions.jl") include(joinpath("tzdata", "TZData.jl")) -is_windows() && include(joinpath("winzone", "WindowsTimeZoneIDs.jl")) +Sys.iswindows() && include(joinpath("winzone", "WindowsTimeZoneIDs.jl")) include("interpret.jl") include("accessors.jl") include("arithmetic.jl") diff --git a/test/runtests.jl b/test/runtests.jl index 6bba9b573..8f88dead3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,7 +11,7 @@ using Base.Test using TimeZones import TimeZones: PKG_DIR, ARCHIVE_DIR import TimeZones.TZData: ZoneDict, RuleDict, tzparse, resolve, build -import Compat: @compat, is_windows +import Compat: @compat, Sys const TZDATA_VERSION = "2016j" const TZ_SOURCE_DIR = get(ENV, "TZ_SOURCE_DIR", joinpath(PKG_DIR, "test", "tzsource")) @@ -44,7 +44,7 @@ include(joinpath("tzdata", "archive.jl")) include(joinpath("tzdata", "version.jl")) include(joinpath("tzdata", "download.jl")) include(joinpath("tzdata", "compile.jl")) -is_windows() && include(joinpath("winzone", "WindowsTimeZoneIDs.jl")) +Sys.iswindows() && include(joinpath("winzone", "WindowsTimeZoneIDs.jl")) include("utcoffset.jl") include("types.jl") include("interpret.jl") From 242803ff32cec83928e09b347a5edda8de30b4b7 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 24 Oct 2017 14:26:54 -0500 Subject: [PATCH 3/7] Fix convert(::Type{Symbol}, ::String) deprecation --- src/types.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types.jl b/src/types.jl index cd2d1497c..3c85d57b5 100644 --- a/src/types.jl +++ b/src/types.jl @@ -33,6 +33,8 @@ struct FixedTimeZone <: TimeZone offset::UTCOffset end +FixedTimeZone(name::AbstractString, offset::UTCOffset) = FixedTimeZone(Symbol(name), offset) + """ FixedTimeZone(name, utc_offset, dst_offset=0) -> FixedTimeZone From a3b353bb9aa9fdb78a6af7598a603d698c842ed5 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 24 Oct 2017 14:37:26 -0500 Subject: [PATCH 4/7] Update deprecated parametric function --- src/types.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.jl b/src/types.jl index 3c85d57b5..612b8a2d9 100644 --- a/src/types.jl +++ b/src/types.jl @@ -268,7 +268,7 @@ end # undefined promote_rule on TimeType types. # Otherwise, typejoin(T,S) is called (returning TimeType) so no conversion happens, and # isless(promote(x,y)...) is called again, causing a stack overflow. -function promote_rule{T<:TimeType,S<:ZonedDateTime}(::Type{T}, ::Type{S}) +function promote_rule(::Type{T}, ::Type{S}) where {T<:TimeType, S<:ZonedDateTime} error("no promotion exists for ", T, " and ", S) end From c8cdf35335255d0c52d293889fabd616fb536807 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 24 Oct 2017 14:37:39 -0500 Subject: [PATCH 5/7] Use Test instead of Base.Test --- REQUIRE | 2 +- test/runtests.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/REQUIRE b/REQUIRE index 7c7780836..e4c9eda7b 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ julia 0.6 -Compat 0.30 +Compat 0.33 Mocking 0.4 @windows LightXML 0.2 diff --git a/test/runtests.jl b/test/runtests.jl index 8f88dead3..515b6de11 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,8 @@ else Mocking.enable() end -using Base.Test +VERSION < v"0.7-" && import Compat: Test +using Test using TimeZones import TimeZones: PKG_DIR, ARCHIVE_DIR import TimeZones.TZData: ZoneDict, RuleDict, tzparse, resolve, build From 62dce499e562e9f8180507db7de6ff11fb1cf73c Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Thu, 2 Nov 2017 07:51:04 -0500 Subject: [PATCH 6/7] Disable compile-modules in Travis CI --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 48a9c8495..9f57b0f34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,9 @@ script: - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi # Avoid setting JULIA_TZ_VERSION if the deps/build.jl file has been modified - git fetch origin +:refs/remotes/origin/HEAD; if ! git diff --quiet origin/HEAD HEAD -- deps/build.jl; then unset JULIA_TZ_VERSION; fi - - OPTIONS=$(julia -e 'isdefined(Base.JLOptions(), :use_compilecache) && print("--compilecache=no")') - - julia $OPTIONS -e 'Pkg.clone(pwd()); Pkg.build("TimeZones"); Pkg.test("TimeZones"; coverage=true)'; + - julia -e 'Pkg.clone(pwd()); Pkg.build("TimeZones")' + - OPTIONS=$(julia -e 'using Mocking; print(DISABLE_PRECOMPILE_STR)') + - julia $OPTIONS -e 'Pkg.test("TimeZones"; coverage=true)' after_success: - julia -e 'cd(Pkg.dir("TimeZones")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; - julia -e 'cd(Pkg.dir("TimeZones")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' From e520c51691b0637d73b835a67fc8f596dea48b53 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Thu, 2 Nov 2017 19:32:56 -0500 Subject: [PATCH 7/7] Fix implicit assignment deprecations Deprecation: "implicit assignment to global variable" --- test/conversions.jl | 3 ++- test/interpret.jl | 1 + test/rounding.jl | 24 ++++++++++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/test/conversions.jl b/test/conversions.jl index 2b9e94f28..01cc26ced 100644 --- a/test/conversions.jl +++ b/test/conversions.jl @@ -34,7 +34,8 @@ zdt_warsaw = ZonedDateTime(dt, warsaw; from_utc=true) @test TimeZones.unix2zdt(0) == ZonedDateTime(1970, utc) for dt in (DateTime(2013, 2, 13), DateTime(2016, 8, 11)) - zdt = ZonedDateTime(dt, warsaw) + local dt + local zdt = ZonedDateTime(dt, warsaw) offset = TimeZones.value(zdt.zone.offset) # Total offset in seconds @test TimeZones.zdt2unix(zdt) == datetime2unix(dt) - offset end diff --git a/test/interpret.jl b/test/interpret.jl index 869a2ba39..ac03277f2 100644 --- a/test/interpret.jl +++ b/test/interpret.jl @@ -56,6 +56,7 @@ non_existent_2 = DateTime(1935,4,1,3) # Both "long" and "hidden" are identical for the following tests for tz in (long, hidden) + local tz boundaries = [ ZonedDateTime(1935, 4, 1, 1, 59, 59, 999, tz), ZonedDateTime(1935, 4, 1, 4, tz), diff --git a/test/rounding.jl b/test/rounding.jl index 8bb59c620..2f7bbd88d 100644 --- a/test/rounding.jl +++ b/test/rounding.jl @@ -22,7 +22,8 @@ colombo = resolve("Asia/Colombo", tzdata["asia"]...) # See note b dt = DateTime(2016) for tz in [utc, fixed, winnipeg, st_johns, eucla, colombo] - zdt = ZonedDateTime(dt, tz) + local tz + local zdt = ZonedDateTime(dt, tz) for p in [Dates.Year, Dates.Month, Dates.Day, Dates.Hour, Dates.Minute, Dates.Second] @test floor(zdt, p) == zdt @test ceil(zdt, p) == zdt @@ -35,7 +36,8 @@ end dt = DateTime(2016, 2, 5, 13, 10, 20, 500) for tz in [utc, fixed, winnipeg, st_johns, eucla, colombo] - zdt = ZonedDateTime(dt, tz) + local tz + local zdt = ZonedDateTime(dt, tz) @test floor(zdt, Dates.Year) == ZonedDateTime(2016, tz) @test floor(zdt, Dates.Month) == ZonedDateTime(2016, 2, tz) @@ -79,7 +81,8 @@ zdt = ZonedDateTime(dt, fixed) @test floor(zdt, Dates.Hour(2)) == ZonedDateTime(2016, 3, 13, 2, fixed) for tz in [winnipeg, st_johns] - zdt = ZonedDateTime(dt, tz) + local tz + local zdt = ZonedDateTime(dt, tz) @test floor(zdt, Dates.Day) == ZonedDateTime(2016, 3, 13, tz) @test floor(zdt, Dates.Hour(2)) == ZonedDateTime(2016, 3, 13, 1, tz) end @@ -95,7 +98,8 @@ zdt = ZonedDateTime(dt, fixed) @test round(zdt, Dates.Minute(30)) == ZonedDateTime(2016, 3, 13, 2, fixed) for tz in [winnipeg, st_johns] - zdt = ZonedDateTime(dt, tz) + local tz + local zdt = ZonedDateTime(dt, tz) @test ceil(zdt, Dates.Day) == ZonedDateTime(2016, 3, 14, tz) @test ceil(zdt, Dates.Hour) == ZonedDateTime(2016, 3, 13, 3, tz) @@ -130,7 +134,8 @@ zdt = ZonedDateTime(dt, fixed) # Rounding to Hour(3) will give 00:00, 03:00, 06:00, 09:00, etc. for tz in [winnipeg, st_johns] - zdt = ZonedDateTime(dt, tz) + local tz + local zdt = ZonedDateTime(dt, tz) @test floor(zdt, Dates.Day) == ZonedDateTime(2015, 11, 1, tz) @test floor(zdt, Dates.Hour(3)) == ZonedDateTime(2015, 11, 1, 1, tz, 1) # Rounding is performed in the current fixed zone, then relocalized if a transition has @@ -148,7 +153,8 @@ zdt = ZonedDateTime(dt, fixed) @test round(zdt, Dates.Minute(30)) == ZonedDateTime(2015, 11, 1, 1, fixed) for tz in [winnipeg, st_johns] - zdt = ZonedDateTime(dt, tz) + local tz + local zdt = ZonedDateTime(dt, tz) next_hour = ZonedDateTime(DateTime(2015, 11, 1, 1), tz, 1) @test ceil(zdt, Dates.Day) == ZonedDateTime(2015, 11, 2, tz) @@ -173,7 +179,8 @@ zdt = ZonedDateTime(dt, fixed) @test round(zdt, Dates.Minute(30)) == ZonedDateTime(2015, 11, 1, 1, 30, fixed) for tz in [winnipeg, st_johns] - zdt = ZonedDateTime(dt, tz, 1) # First 1:25, before "falling back" + local tz + local zdt = ZonedDateTime(dt, tz, 1) # First 1:25, before "falling back" prev_hour = ZonedDateTime(2015, 11, 1, 1, tz, 1) between_hours = ZonedDateTime(2015, 11, 1, 1, 30, tz, 1) next_hour = ZonedDateTime(2015, 11, 1, 1, tz, 2) @@ -242,7 +249,8 @@ zdt = ZonedDateTime(1996, 10, 26, 0, 15, colombo, 2) dt = DateTime(2016, 2, 28, 12, 15, 10, 190) for tz in [utc, fixed, winnipeg, st_johns, eucla, colombo] - zdt = ZonedDateTime(dt, tz) + local tz + local zdt = ZonedDateTime(dt, tz) for p in [Dates.Year, Dates.Month, Dates.Day, Dates.Hour, Dates.Minute, Dates.Second] for v in [-1, 0] @test_throws DomainError floor(dt, p(v))