Skip to content

RFC: Time range implementation #20

@Beforerr

Description

@Beforerr

RFC: Time range type

Feature request:

  • An iterable but not broadcastable time range type
  • Interval arithmetic should just work

References

using Intervals: Bound, AbstractInterval, Closed

struct TimeRange{T, L <: Bound, R <: Bound} <: AbstractInterval{T, L, R}
    first::T
    last::T
end

TimeRange{T}(f, l) where {T} = TimeRange{T, Closed, Closed}(f, l)
TimeRange(f::T, l::T) where {T} = TimeRange{T}(f, l)

function Base.iterate(S::TimeRange, state = 1)
    state > 2 && return nothing
    state == 1 && return S.first, 2
    return state == 2 && return S.last, 3
end
Base.size(S::TimeRange) = (2,)
Base.length(S::TimeRange) = 2
function Base.getindex(S::TimeRange, i::Int)
    i == 1 && return S.first
    i == 2 && return S.last
    throw(BoundsError(S, i))
end
Base.lastindex(S::TimeRange) = 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions