Skip to content

Commit

Permalink
Merge pull request #94 from JuliaTime/cv/compat
Browse files Browse the repository at this point in the history
Compatibility changes for latest Julia 0.7
  • Loading branch information
omus authored Nov 3, 2017
2 parents a42eb12 + e520c51 commit ece22b3
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 34 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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())'
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
Compat 0.27
Mocking 0.2
Compat 0.33
Mocking 0.4
@windows LightXML 0.2
6 changes: 3 additions & 3 deletions src/TimeZones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/local.jl
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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"#.*", ""))
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -266,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

Expand Down
4 changes: 2 additions & 2 deletions src/tzdata/version.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion test/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions test/local_mocking.jl
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -13,22 +13,22 @@ 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
@test localzone() == timezone
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
Expand Down
24 changes: 16 additions & 8 deletions test/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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()
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
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"))
Expand Down Expand Up @@ -45,7 +45,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")
Expand All @@ -57,7 +57,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")

0 comments on commit ece22b3

Please sign in to comment.