Skip to content

Commit 3148bae

Browse files
author
hhaensel
committed
specialize Base.convert(::<:Period, CompoundPeriod) for julia < 1.8
1 parent 9864173 commit 3148bae

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Convert/Convert.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ import ..Core: pyconvert
5151

5252
# patch conversion to Period types for julia <= 1.7
5353
@static if VERSION < v"1.8.0-"
54-
Base.convert(::Type{T}, x::CompoundPeriod) where T<:Period =
55-
isconcretetype(T) ? sum(T, x.periods; init = zero(T)) : throw(MethodError(convert,(T,x)))
54+
for T in (:Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond, :Microsecond, :Nanosecond)
55+
@eval Base.convert(::Type{$T}, x::CompoundPeriod) = sum($T, x.periods; init = zero($T))
56+
end
5657
end
5758

5859
include("pyconvert.jl")

0 commit comments

Comments
 (0)