Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Iterating in reverse #37

Open
Sennahoi opened this issue May 25, 2018 · 2 comments
Open

Question: Iterating in reverse #37

Sennahoi opened this issue May 25, 2018 · 2 comments

Comments

@Sennahoi
Copy link

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?

@dmfs
Copy link
Owner

dmfs commented May 25, 2018

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.

@Sennahoi
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants