Skip to content

Commit

Permalink
Drop unnecessary code paths to support Julia < 1.6 (#187)
Browse files Browse the repository at this point in the history
* Drop `isdisjoint` export

* Drop serialized headers below Julia 1.6

* Hardcode period printing in tests

* Hardcode date printing in tests

* Hardcode ZonedDateTime printing in tests

* Always run doctests

* Revise serialized header

Co-authored-by: David F Little <david.frank.little@gmail.com>
  • Loading branch information
omus and haberdashPI authored May 5, 2022
1 parent e04f9d4 commit cccfa7b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 90 deletions.
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ makedocs(;
authors="Invenia Technical Computing Corporation",
checkdocs=:exports,
strict=true,
# Note: The output of the doctests currently requires a newer version of Julia
doctest=(VERSION >= v"1.5.0-DEV.163"), # https://github.com/JuliaLang/julia/pull/34387
doctest=true,
)

deploydocs(;
Expand Down
1 change: 0 additions & 1 deletion src/Intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export Bound,
union!,
less_than_disjoint,
greater_than_disjoint,
isdisjoint,
superset,
.., , , , , ,
end
110 changes: 36 additions & 74 deletions test/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,6 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded
end

@testset "display" begin
# Notes on compatibility changes and when they can be updated:
#
# When the minimum version of TimeZones requires that `repr` is fixed
# - `repr(ZonedDateTime(...))` and `$ZonedDateTime` can be changed to be hardcoded
#
# When dropping VERSION < v"1.2.0-DEV.29" (https://github.com/JuliaLang/julia/pull/30200)
# - `repr(Date(...))` and `repr(DateTime(...))` can be converted to hardcode strings
#
# When dropping VERSION < v"1.2.0-DEV.223" (https://github.com/JuliaLang/julia/pull/30817)
# - `repr(Period(...))`can be converted to hardcode strings

where_lr = "where {L<:$Bounded, R<:$Bounded}"
where_tlr = "where {T, L<:$Bounded, R<:$Bounded}"

Expand All @@ -254,149 +243,122 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded
@test sprint(show, AnchoredInterval{Hour(1)}) ==
"HourBeginning"
@test sprint(show, AnchoredInterval{Day(-1)}) ==
"AnchoredInterval{$(repr(Day(-1)))}"
"AnchoredInterval{Day(-1)}"
@test sprint(show, AnchoredInterval{Day(1)}) ==
"AnchoredInterval{$(repr(Day(1)))}"
"AnchoredInterval{Day(1)}"
@test sprint(show, AnchoredInterval{Day(-1), DateTime}) ==
"AnchoredInterval{$(repr(Day(-1))), DateTime}"
"AnchoredInterval{Day(-1), DateTime}"
@test sprint(show, AnchoredInterval{Day(1), DateTime}) ==
"AnchoredInterval{$(repr(Day(1))), DateTime}"
"AnchoredInterval{Day(1), DateTime}"
else
@test sprint(show, AnchoredInterval{Hour(-1)}) ==
"HourEnding{T, L, R} $where_tlr"
@test sprint(show, AnchoredInterval{Hour(1)}) ==
"HourBeginning{T, L, R} $where_tlr"
@test sprint(show, AnchoredInterval{Day(-1)}) ==
"AnchoredInterval{$(repr(Day(-1))), T, L, R} $where_tlr"
"AnchoredInterval{Day(-1), T, L, R} $where_tlr"
@test sprint(show, AnchoredInterval{Day(1)}) ==
"AnchoredInterval{$(repr(Day(1))), T, L, R} $where_tlr"
"AnchoredInterval{Day(1), T, L, R} $where_tlr"
@test sprint(show, AnchoredInterval{Day(-1), DateTime}) ==
"AnchoredInterval{$(repr(Day(-1))), DateTime, L, R} $where_lr"
"AnchoredInterval{Day(-1), DateTime, L, R} $where_lr"
@test sprint(show, AnchoredInterval{Day(1), DateTime}) ==
"AnchoredInterval{$(repr(Day(1))), DateTime, L, R} $where_lr"
"AnchoredInterval{Day(1), DateTime, L, R} $where_lr"
end

# Tuples contain fields: interval, printed, shown
tests = [
(
HourEnding(dt),
"(2016-08-11 HE02]",
string(
"HourEnding{DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2))))",
),
"HourEnding{DateTime, Open, Closed}(DateTime(\"2016-08-11T02:00:00\"))",
),
(
HourEnding{Closed, Open}(DateTime(2013, 2, 13)),
"[2013-02-12 HE24)",
string(
"HourEnding{DateTime, Closed, Open}",
"($(repr(DateTime(2013, 2, 13))))",
),
"HourEnding{DateTime, Closed, Open}(DateTime(\"2013-02-13T00:00:00\"))",
),
(
HourEnding(dt + Minute(15) + Second(30)),
"(2016-08-11 HE02:15:30]",
string(
"HourEnding{DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2, 15, 30))))",
),
"HourEnding{DateTime, Open, Closed}(DateTime(\"2016-08-11T02:15:30\"))",
),
(
HourEnding(dt + Millisecond(2)),
"(2016-08-11 HE02:00:00.002]",
string(
"HourEnding{DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2, 0, 0, 2))))",
),
"HourEnding{DateTime, Open, Closed}(DateTime(\"2016-08-11T02:00:00.002\"))",
),
(
HourEnding{Closed, Open}(DateTime(2013, 2, 13, 0, 1)),
"[2013-02-13 HE00:01:00)",
string(
"HourEnding{DateTime, Closed, Open}",
"($(repr(DateTime(2013, 2, 13, 0, 1))))",
),
"HourEnding{DateTime, Closed, Open}(DateTime(\"2013-02-13T00:01:00\"))",
),
(
HourBeginning(dt),
"[2016-08-11 HB02)",
string(
"HourBeginning{DateTime, Closed, Open}",
"($(repr(DateTime(2016, 8, 11, 2))))",
),
"HourBeginning{DateTime, Closed, Open}(DateTime(\"2016-08-11T02:00:00\"))",
),
(
HourBeginning{Open, Closed}(DateTime(2013, 2, 13)),
"(2013-02-13 HB00]",
string(
"HourBeginning{DateTime, Open, Closed}",
"($(repr(DateTime(2013, 2, 13))))",
),
"HourBeginning{DateTime, Open, Closed}(DateTime(\"2013-02-13T00:00:00\"))",
),
(
HourEnding(ZonedDateTime(dt, tz"America/Winnipeg")),
"(2016-08-11 HE02-05:00]",
string(
"HourEnding{$ZonedDateTime, Open, Closed}",
"($(repr(ZonedDateTime(dt, tz"America/Winnipeg"))))",
"(ZonedDateTime(2016, 8, 11, 2, tz\"America/Winnipeg\"))",
),
),
(
AnchoredInterval{Year(-1)}(Date(dt)),
"(YE 2016-08-11]",
string(
"AnchoredInterval{$(repr(Year(-1))), Date, Open, Closed}",
"($(repr(Date(2016, 8, 11))))",
),
"AnchoredInterval{Year(-1), Date, Open, Closed}(Date(\"2016-08-11\"))",
),
(
AnchoredInterval{Year(-1)}(ceil(Date(dt), Year)),
"(YE 2017-01-01]",
string(
"AnchoredInterval{$(repr(Year(-1))), Date, Open, Closed}",
"($(repr(Date(2017, 1, 1))))",
),
"AnchoredInterval{Year(-1), Date, Open, Closed}(Date(\"2017-01-01\"))",
),
(
AnchoredInterval{Month(-1)}(dt),
"(MoE 2016-08-11 02:00:00]",
string(
"AnchoredInterval{$(repr(Month(-1))), DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2, 0, 0))))",
"AnchoredInterval{Month(-1), DateTime, Open, Closed}",
"(DateTime(\"2016-08-11T02:00:00\"))",
),
),
(
AnchoredInterval{Month(-1)}(ceil(dt, Month)),
"(MoE 2016-09-01]",
string(
"AnchoredInterval{$(repr(Month(-1))), DateTime, Open, Closed}",
"($(repr(DateTime(2016, 9, 1))))",
"AnchoredInterval{Month(-1), DateTime, Open, Closed}",
"(DateTime(\"2016-09-01T00:00:00\"))",
),
),
(
AnchoredInterval{Day(-1)}(DateTime(dt)),
"(DE 2016-08-11 02:00:00]",
string(
"AnchoredInterval{$(repr(Day(-1))), DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2))))",
"AnchoredInterval{Day(-1), DateTime, Open, Closed}",
"(DateTime(\"2016-08-11T02:00:00\"))",
),
),
(
AnchoredInterval{Day(-1)}(ceil(DateTime(dt), Day)),
"(DE 2016-08-12]",
string(
"AnchoredInterval{$(repr(Day(-1))), DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 12))))",
"AnchoredInterval{Day(-1), DateTime, Open, Closed}",
"(DateTime(\"2016-08-12T00:00:00\"))",
),
),
(
# Date(dt) will truncate the DateTime to the nearest day
AnchoredInterval{Day(-1)}(Date(dt)),
"(DE 2016-08-11]",
string(
"AnchoredInterval{$(repr(Day(-1))), Date, Open, Closed}",
"($(repr(Date(2016, 8, 11))))",
"AnchoredInterval{Day(-1), Date, Open, Closed}",
"(Date(\"2016-08-11\"))",
),
),
(
Expand All @@ -407,32 +369,32 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded
),
"(DE 2016-08-12 00:00:00-05:00]",
string(
"AnchoredInterval{$(repr(Day(-1))), $ZonedDateTime, Open, Closed}",
"($(repr(ZonedDateTime(2016, 8, 12, tz"America/Winnipeg"))))",
"AnchoredInterval{Day(-1), $ZonedDateTime, Open, Closed}",
"(ZonedDateTime(2016, 8, 12, tz\"America/Winnipeg\"))",
),
),
(
AnchoredInterval{Minute(-5)}(dt),
"(2016-08-11 5ME02:00]",
string(
"AnchoredInterval{$(repr(Minute(-5))), DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2))))",
"AnchoredInterval{Minute(-5), DateTime, Open, Closed}",
"(DateTime(\"2016-08-11T02:00:00\"))",
),
),
(
AnchoredInterval{Second(-30)}(dt),
"(2016-08-11 30SE02:00:00]",
string(
"AnchoredInterval{$(repr(Second(-30))), DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2))))",
"AnchoredInterval{Second(-30), DateTime, Open, Closed}",
"(DateTime(\"2016-08-11T02:00:00\"))",
),
),
(
AnchoredInterval{Millisecond(-10)}(dt),
"(2016-08-11 10msE02:00:00.000]",
string(
"AnchoredInterval{$(repr(Millisecond(-10))), DateTime, Open, Closed}",
"($(repr(DateTime(2016, 8, 11, 2))))",
"AnchoredInterval{Millisecond(-10), DateTime, Open, Closed}",
"(DateTime(\"2016-08-11T02:00:00\"))",
),
),
]
Expand Down
17 changes: 4 additions & 13 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
# Note: To support testing against the latest Julia nightly we'll assume the serialization
# format is the same as the last version of Julia we've tested against.
const SERIALIZED_HEADER = if VERSION >= v"1.5"
"7JL\n\x04\0\0"
elseif VERSION >= v"1.4"
"7JL\t\x04\0\0"
elseif VERSION >= v"1.2"
"7JL\b\x04\0\0"
elseif VERSION >= v"1.0"
"7JL\a\x04\0\0"
else
error("Julia versions earlier than 1.0 are unsupported")
end
# The serialization header can change between Julia versions. When the header does change
# then we can expect the "legacy deserialization" testset to fail and we'll need to
# conditionally set the value of the header here.
const SERIALIZED_HEADER = "7JL\n\x04\0\0" # Header for Julia 1.5+

# Declare a new `isnan` and `isinf` functions to avoid type piracy. These new function work
# with `Char` and `Period` types as well as other types.
Expand Down

0 comments on commit cccfa7b

Please sign in to comment.