Skip to content

Commit

Permalink
Support signbit(::Dates.Period) (#51073)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Feb 15, 2024
1 parent 1b25d1e commit e460d35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/Dates/src/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ div(x::Period, y::Period, r::RoundingMode) = div(promote(x, y)..., r)
Base.gcdx(a::T, b::T) where {T<:Period} = ((g, x, y) = gcdx(value(a), value(b)); return T(g), x, y)
Base.abs(a::T) where {T<:Period} = T(abs(value(a)))
Base.sign(x::Period) = sign(value(x))
Base.signbit(x::Period) = signbit(value(x))

# return (next coarser period, conversion factor):
coarserperiod(::Type{P}) where {P<:Period} = (P, 1)
Expand Down
3 changes: 3 additions & 0 deletions stdlib/Dates/test/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ using Test
@test sign(t) == sign(t2) == 1
@test sign(-t) == sign(-t2) == -1
@test sign(Dates.Year(0)) == 0
@test signbit(t) == signbit(t2) == false
@test signbit(-t) == signbit(-t2) == true
@test signbit(Dates.Year(0)) == false
end
@testset "div/mod/gcd/lcm/rem" begin
@test Dates.Year(10) % Dates.Year(4) == Dates.Year(2)
Expand Down

0 comments on commit e460d35

Please sign in to comment.