# Interpolate Dates

#1

Similar to this, I am interested in writing an interpolation for Date(Times).

``````julia> using Interpolations

julia> dates = [Dates.today()+Dates.Year(i-1) for i in 1:6]
6-element Array{Date,1}:
2018-01-01
2019-01-01
2020-01-01
2021-01-01
2022-01-01
2023-01-01

julia> values = [Float64(i-1) for i in 1:6]
6-element Array{Float64,1}:
0.0
1.0
2.0
3.0
4.0
5.0

julia> int = interpolate((dates,),values,Gridded(Linear()));

julia> int[Dates.today()+Dates.Month(6)]
ERROR: MethodError: no method matching length(::Date)
Closest candidates are:
length(::SimpleVector) at essentials.jl:256
length(::Base.MethodList) at reflection.jl:558
length(::MethodTable) at reflection.jl:634
...
Stacktrace:
[1] getindex(::Interpolations.GriddedInterpolation{Float64,1,Float64,Interpolations.Gridded{Interpolations.Linear},Tuple{Array{Date,1}},0}, ::Date) at C:\Users\Eric\.julia\v0.6\Interpolations\src\gridded\indexing.jl:96
``````

Any ideas?

#2

Looks like it’s mainly because `length(::Date)` isn’t defined. You could do `eval(Base, :(length(::Date) = 1))` and see how far you get after that. If that’s all that’s needed, we could add that definition to `stdlib/Dates`, since I think we define that for Numbers anyway.

#3

Numbers are iterable though. Maybe that makes a difference.