It should be easier/cleaner than
ClearAll[tsNew]
tsNew[s_, tf_, foo_] := Module[{tsw = TimeSeriesWindow[s, {s["FirstTime"], tf}],
bar, tsX, rules},
tsX = TimeSeries[Array[x, {Length@tsw["Values"]}], Automatic];
rules = Dispatch[Thread[tsX["Values"] -> tsw["Values"]]];
Accumulate[TimeSeriesMap[bar, tsX]] /. Plus -> foo /.
foo[x__] :> foo[## & @@ ({x} /. bar -> Identity)] /. bar -> foo /. rules]
Example:
v = {2, 1, 6, 5, 7, 4};
t = {1, 2, 5, 10, 12, 15};
ts = TimeSeries[v, {t}];
ts["Path"]
{{1, 2}, {2, 1}, {5, 6}, {10, 5}, {12, 7}, {15, 4}}
tsNew[ts, 10, f]["Path"]
{{0, f[2]}, {1, f[2, 1]}, {2, f[2, 1, 6]}, {3, f[2, 1, 6, 5]}}
tsNew[ts, 20, f]["Path"]
{{0, f[2]}, {1, f[2, 1]}, {2, f[2, 1, 6]}, {3, f[2, 1, 6, 5]},
{4, f[2, 1, 6, 5, 7]}, {5, f[2, 1, 6, 5, 7, 4]}}