JuliaStats / TimeSeries.jl

Time series toolkit for Julia
Other
349 stars 69 forks source link

Type parameter for Date vs DateTime? #207

Closed GordStephen closed 8 years ago

GordStephen commented 8 years ago

Thinking about how to approach the remaining issues in #190, it occurs to me that it would be useful to be able to define methods specific to Date- vs DateTime-indexed arrays. One approach might be to specify the TimeType as a TimeArray type parameter. The type definition might look something like:

immutable TimeArray{T,N,D<:TimeType,M} <: AbstractTimeSeries

    timestamp::Vector{D}
    values::AbstractArray{T,N}
    colnames::Vector{UTF8String}
    meta::M

One could then write things like:

function from{T,N,D}(ta::TimeArray{T,N,D}, starttime::D)
...

Any thoughts?

milktrader commented 8 years ago

I presume that the Dates package in Base has an abstract TimeType that parents Date and DateTime.

@quinnj ?

GordStephen commented 8 years ago

Yep, correct.

julia> subtypes(Dates.TimeType)
2-element Array{Any,1}:
 Base.Dates.Date    
 Base.Dates.DateTime
milktrader commented 8 years ago

Interesting. Starting to think about your interface above. It looks elegant and presumably solves the issue about supporting both Date and DateTime operations, no?

GordStephen commented 8 years ago

Yeah, exactly. It would also theoretically support any new or custom TimeTypes that were to come along in the future.

milktrader commented 8 years ago

Good point, like a Ticktime type maybe for high frequency trading

GordStephen commented 8 years ago

Added in #223