diff --git a/Project.toml b/Project.toml index 02abf1c..4b51c47 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "TimeArrays" uuid = "058eeebf-2231-41de-8410-62311c15f51e" -version = "1.0.1" +version = "1.1.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/interface.jl b/src/interface.jl index 340eac6..c7dcc37 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -31,11 +31,11 @@ struct TimeTick{T<:TimeLike,V<:Any} <: AbstractTick{T,V} end function TimeTick{T,V}(x::Tuple{TimeLike,Any}) where {T<:TimeLike,V} - return new{T,V}(x...) + return new{T,V}(x[1], x[2]) end function TimeTick{T,V}(x::NamedTuple{names,<:Tuple{TimeLike,Any}} where {names}) where {T<:TimeLike,V} - return new{T,V}(x...) + return new{T,V}(x[1], x[2]) end function TimeTick{T,V}(x::Pair{<:TimeLike,<:Any}) where {T<:TimeLike,V} @@ -86,7 +86,7 @@ TimeTick(2024-01-01T00:00:00, 100) ``` """ function TimeTick(x::Tuple{T,V}) where {T<:TimeLike,V} - return TimeTick{T,V}(x...) + return TimeTick{T,V}(x[1], x[2]) end """ @@ -107,7 +107,7 @@ TimeTick(2024-01-01T00:00:00, 100) ``` """ function TimeTick(x::NamedTuple{names,Tuple{T,V}}) where {names,T<:TimeLike,V} - return TimeTick{T,V}(x...) + return TimeTick{T,V}(x[1], x[2]) end """ @@ -168,6 +168,22 @@ function Base.convert(::Type{TimeTick{T,V}}, value::Pair{TimeLike,Any}) where {T return TimeTick{T,V}(value) end +function Base.convert(::Type{Tuple}, timetick::TimeTick) + return Tuple(timetick) +end + +function Base.convert(::Type{Tuple{T,V}}, timetick::TimeTick) where {T<:TimeLike,V} + return Tuple{T,V}(timetick) +end + +function Base.convert(::Type{Pair}, timetick::TimeTick) + return Pair(x.first, x.second) +end + +function Base.convert(::Type{Pair{T,V}}, timetick::TimeTick) where {T<:TimeLike,V} + return Pair{T,V}(x.first, x.second) +end + function Base.getindex(t::TimeTick, i::Integer) i == 1 && return ta_timestamp(t) i == 2 && return ta_value(t) @@ -203,7 +219,7 @@ end Supertype for `TimeArray{T,V}` with timestamps of type `T` and values of type `V`. """ -abstract type AbstractTimeArray{T,V} <: AbstractVector{TimeTick{T,V}} end +abstract type AbstractTimeArray{T,V} <: AbstractVector{AbstractTick{T,V}} end """ TimeArray{T,V} <: AbstractTimeArray{T,V}