Types
TimeArrays.TimeLike
— TypeTimeLike <: Union{Dates.TimeType,Real}
TimeArray
's timestamp type that accepts Dates.TimeType
and Real
.
TimeArrays.PeriodLike
— TypePeriodLike <: Union{Dates.Period,Real}
TimeArray
's period type that accepts Dates.Period
and Real
.
TimeTick
TimeArrays.AbstractTick
— TypeAbstractTick{T,V}
Supertype for TimeTick{T,V}
with timestamp of type T
and value of type V
.
TimeArrays.TimeTick
— TypeTimeTick{T,V} <: AbstractTick{T,V}
A type describing a timestamp of type T<:TimeLike
and its value of type V
.
Fields
timestamp::T
: The timestamp.value::V
: The value.
Accessors
ta_timestamp(x::TimeTick)
->x.timestamp
ta_value(x::TimeTick)
->x.value
TimeArrays.TimeTick
— MethodTimeTick{T,V}(timestamp::TimeLike, value)
TimeTick(timestamp::T, value::V)
Constructs a TimeTick
object with the passed timestamp
and value
.
Examples
julia> using Dates
julia> TimeTick{Date,Float64}(DateTime("2024-01-01T00:00:00"), 100)
TimeTick(2024-01-01, 100.0)
julia> TimeTick(DateTime("2024-01-01T00:00:00"), 100)
TimeTick(2024-01-01T00:00:00, 100)
TimeTick{T,V}(x::Tuple{TimeLike,Any})
TimeTick(x::Tuple{T,V})
Constructs a TimeTick
object from tuple x
which contains the timestamp and value.
Examples
julia> using Dates
julia> TimeTick{Date,Float64}((DateTime("2024-01-01T00:00:00"), 100))
TimeTick(2024-01-01, 100.0)
julia> TimeTick((DateTime("2024-01-01T00:00:00"), 100))
TimeTick(2024-01-01T00:00:00, 100)
TimeTick{T,V}(x::NamedTuple{_,Tuple{TimeLike,Any}})
TimeTick(x::NamedTuple{_,Tuple{TimeLike,Any}})
Constructs a TimeTick
object from named tuple x
which contains the timestamp and value.
Examples
julia> using Dates
julia> TimeTick{Date,Float64}((timestamp = DateTime("2024-01-01T00:00:00"), value = 100))
TimeTick(2024-01-01, 100.0)
julia> TimeTick((timestamp = DateTime("2024-01-01T00:00:00"), value = 100))
TimeTick(2024-01-01T00:00:00, 100)
TimeTick{T,V}(x::Pair{TimeLike,Number})
TimeTick(x::Pair{T,V})
Constructs a TimeTick
object from pair x
which contains the timestamp and value.
Examples
julia> using Dates
julia> TimeTick{Date,Float64}(DateTime("2024-01-01T00:00:00") => 100)
TimeTick(2024-01-01, 100.0)
julia> TimeTick(DateTime("2024-01-01T00:00:00") => 100)
TimeTick(2024-01-01T00:00:00, 100)
TimeArray
TimeArrays.AbstractTimeArray
— TypeAbstractTimeArray{T,V} <: AbstractVector{TimeTick{T,V}}
Supertype for TimeArray{T,V}
with timestamps of type T
and values of type V
.
TimeArrays.TimeArray
— TypeTimeArray{T,V} <: AbstractTimeArray{T,V}
Type describing a time series with timestamps of type T
and values of type V
.
Fields
values::Vector{TimeTick{T,V}}
: Elements of a time series.length::Int64
: The length of the underlying array.
Accessors
ta_values(x::TimeArray)
->x.values
TimeArrays.TimeArray
— MethodTimeArray{T,V}(values::Vector{TimeTick})
TimeArray(values::Vector{TimeTick{T,V}})
Creates a TimeArray{T,V}
object from values
and sorts them by date in ascending order.
Examples
julia> using Dates
julia> values = [
TimeTick(DateTime("2022-1-1T00:00:00"), 3),
TimeTick(DateTime("2023-1-1T00:00:00"), 1),
TimeTick(DateTime("2021-1-1T00:00:00"), 2),
];
julia> TimeArray{Date,Float64}(values)
3-element TimeArray{Date, Float64}:
TimeTick(2021-01-01, 2.0)
TimeTick(2022-01-01, 3.0)
TimeTick(2023-01-01, 1.0)
julia> TimeArray(values)
3-element TimeArray{DateTime, Int64}:
TimeTick(2021-01-01T00:00:00, 2)
TimeTick(2022-01-01T00:00:00, 3)
TimeTick(2023-01-01T00:00:00, 1)
TimeArray(iter)
TimeArray{T,V}(iter)
Creates a TimeArray{T,V}
object from iter
values and sorts them by date in ascending order.
julia> struct TimeTickIter
state::Int
end;
julia> Base.length(x::TimeTickIter) = x.state;
julia> function Base.iterate(x::TimeTickIter, state = 1)
return state <= x.state ? (TimeTick(state, state), state + 1) : nothing
end;
julia> TimeArray(TimeTickIter(5))
5-element TimeArray{Int64, Int64}:
TimeTick(1, 1)
TimeTick(2, 2)
TimeTick(3, 3)
TimeTick(4, 4)
TimeTick(5, 5)
julia> TimeArray{Float64,Float64}(TimeTickIter(5))
5-element TimeArray{Float64, Float64}:
TimeTick(1.0, 1.0)
TimeTick(2.0, 2.0)
TimeTick(3.0, 3.0)
TimeTick(4.0, 4.0)
TimeTick(5.0, 5.0)
TimeArray(values::Vector{Pair{T,V}})
TimeArray(values::Vector{Tuple{TimeLike,Any}})
TimeArray(values::Vector{NamedTuple{_,Tuple{T,V}}})
Creates a TimeArray{T,V}
object from values
and sorts them by date in ascending order.
Examples
julia> using Dates
julia> TimeArray([
DateTime("2024-01-02T00:00:00") => 3,
DateTime("2024-01-03T00:00:00") => 1,
DateTime("2024-01-01T00:00:00") => 2,
])
3-element TimeArray{DateTime, Int64}:
TimeTick(2024-01-01T00:00:00, 2)
TimeTick(2024-01-02T00:00:00, 3)
TimeTick(2024-01-03T00:00:00, 1)
julia> TimeArray([
(DateTime("2024-01-02T00:00:00"), 3),
(DateTime("2024-01-03T00:00:00"), 1),
(DateTime("2024-01-01T00:00:00"), 2),
])
3-element TimeArray{DateTime, Int64}:
TimeTick(2024-01-01T00:00:00, 2)
TimeTick(2024-01-02T00:00:00, 3)
TimeTick(2024-01-03T00:00:00, 1)
julia> TimeArray([
(time = DateTime("2024-01-02T00:00:00"), value = 3),
(time = DateTime("2024-01-03T00:00:00"), value = 1),
(time = DateTime("2024-01-01T00:00:00"), value = 2),
])
3-element TimeArray{DateTime, Int64}:
TimeTick(2024-01-01T00:00:00, 2)
TimeTick(2024-01-02T00:00:00, 3)
TimeTick(2024-01-03T00:00:00, 1)
TimeArray(timestamps::Vector{TimeLike}, values::Vector{Any})
Creates a TimeArray
by "zipping" together elements of timestamps
and values
.
Examples
julia> using Dates
julia> timestamps = [
DateTime("2024-01-02"),
DateTime("2024-01-03"),
DateTime("2024-01-01"),
];
julia> values = [2.0, 1.0, 3.0];
julia> TimeArray(timestamps, values)
3-element TimeArray{DateTime, Float64}:
TimeTick(2024-01-01T00:00:00, 3.0)
TimeTick(2024-01-02T00:00:00, 2.0)
TimeTick(2024-01-03T00:00:00, 1.0)
TimeArray{T,V}(values::AbstractVector)
Creates a TimeArrays{T,V}
from a values
that contains any elements that can be passed to TimeTick{T,V}
constructors.
This approach greatly reduces performance. Use at your own discretion.
Examples
julia> using Dates
julia> values = [
TimeTick(Date("2024-01-02"), 3.0),
(DateTime("2024-01-03"), 1.0),
Date("2024-01-01") => 2,
];
julia> TimeArray{Date,Int64}(values)
3-element TimeArray{Date, Int64}:
TimeTick(2024-01-01, 2)
TimeTick(2024-01-02, 3)
TimeTick(2024-01-03, 1)