Skip to content

Commit

Permalink
specialize Base.convert(::<:Period, CompoundPeriod) for julia < 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 21, 2025
1 parent 9864173 commit 3148bae
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Convert/Convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ import ..Core: pyconvert

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

include("pyconvert.jl")
Expand Down

0 comments on commit 3148bae

Please sign in to comment.