Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add promoting ops for Dates.Period #782

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,17 @@ if VERSION < v"1.8.0-DEV.1494" # 98e60ffb11ee431e462b092b48a31a1204bd263d
allequal(r::AbstractRange) = iszero(step(r)) || length(r) <= 1
end

# https://github.com/JuliaLang/julia/commit/bdf9ead91e5a8dfd91643a17c1626032faada329
if VERSION < v"1.8.0-DEV.1109"
# we do not add the methods for == and isless that are included in the above
# commit, since they are already present in earlier versions.
import Base: /, rem, mod, lcm, gcd, div
for op in (:/, :rem, :mod, :lcm, :gcd)
@eval ($op)(x::Period, y::Period) = ($op)(promote(x, y)...)
end
div(x::Period, y::Period, r::RoundingMode) = div(promote(x, y)..., r)
end

# This function is available as of Julia 1.7.
@static if !isdefined(Base, :keepat!)
export keepat!
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,15 @@ end
@test_throws ArgumentError stack([])
@test_throws ArgumentError stack(x for x in 1:3 if false)
end

@testset "promoting ops for TimePeriod" begin
x = 10
y = 3
xs = Second(x)
ys = Second(y)
xms = Millisecond(xs)
yms = Millisecond(ys)
for op in (/, div, rem, mod, lcm, gcd)
@test op(xms, yms) == op(xms, ys) == op(xs, yms)
end
end