lib-recur
lib-recur copied to clipboard
Question: Iterating in reverse
Hello. Is it possible to iterate over the events in reverse order? I don't see any code for this and RecurrenceRuleIterator seems to work only in one direction. If it's not possible, could you give me a hint how I could implement that myself?
We don't have anything like that in place yet. I'm not even sure there is a practical solution to this. For infinite rules this is apparently impossible unless you start somewhere in the middle. For finite rules you could just put all the results onto a stack and re-iterate the stack from the top. In order to truly iterate backwards you'd have to find a event to start from which matches the rule with the given start event. That can be quite a challenge. I'll need some time to think about this. We could use something like that for "fast-forward" purposes as well.
I guess I stated the problem way too general. The problem I'm facing is, starting from now (or another point in time in the middle), how can I calculate the the event just before now. A brute force like approach could be to calculate the distance between two events, fast-forward to (now-2xdistance) and calculate the next event.
In simple cases, this may work. But, for example, finding the last 29.02. requires to go back 4 years and the that's just the first special case that comes to my mind.