Skip to content

0-length index into a StepRange of TimePeriod errors #57056

Open
@tiemvanderdeure

Description

@tiemvanderdeure

For example:

using Dates
(Dates.Hour(1):Dates.Hour(1):Dates.Hour(2))[1:0]

Errors with

ERROR: MethodError: no method matching copysign(::Hour, ::Hour)
The function `copysign` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  copysign(::Float64, ::Float64)
   @ Base floatfuncs.jl:5
  copysign(::Float64, ::Real)
   @ Base floatfuncs.jl:8
  copysign(::Float32, ::Float32)
   @ Base floatfuncs.jl:6
  ...

Stacktrace:
 [1] getindex(r::StepRange{Hour, Hour}, s::UnitRange{Int64})
   @ Base .\range.jl:1029
 [2] top-level scope

A possible fix would be to define Base.copysign on TimePeriod. The below works

import Dates.value
Base.copysign(x::T, y::T) where T<:TimePeriod = T(copysign(value(x), value(y)))

(Dates.Hour(1):Dates.Hour(1):Dates.Hour(2))[1:0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviordatesDates, times, and the Dates stdlib module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions