Skip to content

Commit

Permalink
test prefix for Quarter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ianlmgoddard committed Apr 21, 2021
1 parent 7245520 commit 0e4fbaa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Intervals"
uuid = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
license = "MIT"
authors = ["Invenia Technical Computing"]
version = "1.5.0"
version = "1.5.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
8 changes: 6 additions & 2 deletions src/description.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function prefix(p::Period)
end

prefix(::Type{Year}) = "Y"
prefix(::Type{Quarter}) = "Q"
prefix(::Type{Month}) = "Mo"
prefix(::Type{Week}) = "W"
prefix(::Type{Day}) = "D"
Expand All @@ -69,5 +68,10 @@ prefix(::Type{Minute}) = "M"
prefix(::Type{Second}) = "S"
prefix(::Type{Millisecond}) = "ms"

# informative error if no prefix is defined for the givne type.
# `Quarter` defined after Julia1.6.
if VERSION >= v"1.6"
prefix(::Type{Quarter}) = "Q"
end

# informative error if no prefix is defined for the given type.
prefix(T::Type{<:Period}) = error("A prefix for period $T has not yet been defined")
26 changes: 25 additions & 1 deletion test/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded
"($(repr(DateTime(2016, 9, 1))))",
),
),
(
AnchoredInterval{Week(-1)}(dt),
"(WE 2016-08-11 02:00:00]",
string(
if VERSION >= v"1.6.0"
"AnchoredInterval{$(repr(Week(-1))), DateTime, Open, Closed}"
else
"AnchoredInterval{$(repr(Week(-1))),DateTime,Open,Closed}"
end,
"($(repr(DateTime(2016, 8, 11, 2, 0, 0))))",
),
),
(
AnchoredInterval{Week(-1)}(ceil(dt, Week)),
"(WE 2016-08-15]",
Expand Down Expand Up @@ -525,9 +537,21 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded
end,
"($(repr(DateTime(2016, 8, 11, 2))))",
),
),
),
]

# add test for `Quarter`, only defined after Julia1.6
if VERSION >= v"1.6"
entry = (AnchoredInterval{Quarter(-1)}(ceil(Date(dt), Quarter)),
"(QE 2016-10-01]",
string(
"AnchoredInterval{$(repr(Quarter(-1))), Date, Open, Closed}",
"($(repr(Date(2016, 10, 01))))",
),
)
push!(tests, entry)
end

for (interval, printed, shown) in tests
@test sprint(print, interval) == printed
@test string(interval) == printed
Expand Down

0 comments on commit 0e4fbaa

Please sign in to comment.