brendanjohnharris / TimeseriesTools.jl

A convenient package for working with time series (time-indexed arrays)
MIT License
16 stars 0 forks source link

Feature Request: Add support for `Dates.DateTime` or equivalent date/time type on x-axis for `TimeseriesTools.TimeSeries` #6

Open gsalaz98 opened 12 months ago

gsalaz98 commented 12 months ago

Hello,

Thank you for this project. I think it's awesome and very much needed in the ecosystem.

I tried using the package to create a time series indexed by Dates.DateTime types, but noticed that there's no first-class support for it yet.

Are there any plans or desire to add that capability in the future? I might be able to contribute some time to the codebase to add that functionality (if I find the time).

Thank you!

brendanjohnharris commented 12 months ago

Hey Gerardo, glad you like the package!

DateTimes should work fine when constructing an AbstractTimeSeries:

x = 1:100
t = DateTime(1901):Year(1):DateTime(2000);
y = TimeSeries(t, x)

And also for some of the simpler methods, such as:

y isa RegularTimeSeries # true
samplingperiod(y) # 1 year
duration(y) # 3124137600000 milliseconds. This would be in Years if e.g. t = Year(1):Year(1):Year(100)
times(y) # DateTime("1901-01-01T00:00:00"):Year(1):DateTime("2000-01-01T00:00:00")

Currently, some methods will fail, such as:

samplingrate(y) # / is undefined for DateTimes and Int's

as well as plotting (since Makie doesn't have recipes defined for DateTime's)

I don't work with DateTimes often (at all...), so I'm not sure what sorts of extra functionality it'd be useful to have for these types of time series. Let me know if you have specific functionality in mind, I'd be more than happy to have a go at adding it, or feel free to open a PR :)

(To make things a bit more convenient, I've just defined some types for DateTime indices: DateIndex, DateTimeIndex, and a DateTimeSeries).