Say I am given a date start
an increment step
(possibly mixed radix) and a desired number of steps n
. I would like to compute a date end
that will satisfy Length[DateRange[start,end,step]]==n
.
I can compute this date end
with the following function.
f[{start_, Automatic, step_}, n_]:= Nest[DatePlus[#, step] &, start, n - 1]
This works nicely in examples where n
is small.
start = {2008, 1, 1};
step = {{1, "Day"}, {5, "Week"}};
n = 50;
AbsoluteTiming[end = f[{start, Automatic, step}, n]]
(* {0.015600, {2012, 10, 30}} *)
DateRange[start, end, step] // Length
(* 50 *)
However, when n
is large, this is terribly slow.
n = 10000;
AbsoluteTiming[end = f[{start, Automatic, step}, n]]
(* {5.148009, {2993, 7, 19}} *)
Is there a significantly faster way to compute the date end
?