Free Support Forum - aspose.com

Quickly determine next occurence based on date / time

Hi,

I am just starting to use iCalendar so I might have missed something. However what I’d like to be able to do is to get the next occurence given a specific date / time. Instead of either getting all occurences or occurences within a time frame (I don’t know whether a given pattern might fall into my time frame), I simply want to pass in a date / time and have the next occurence (date / time again) be returned or DateTime.MinValue if there isn’t any next occurence.

Any hints on this?

Regards

Kai

Good question. I'm sure it was discussed before, but I cannot find a relevant post.

The problem is that it is not computationally possible to determine just "next" occurrence after an arbitrary date without the pattern internally calculating all occurrences from the beginning of the pattern. Hence the current API that either requests you to provide a window of dates where you want occurrences calculated or calculates all occurrences of the pattern.

An easy example that comes to mind is: "Friday, Every 2nd week".

Such a pattern only makes sense if it has a start date. Without a start date you cannot tell which week is second (even) and which is first (odd).

One has to calculate all occurrences from the start date of the pattern, otherwise it is not known which week to pick. I hope you can see that.

Roman,

of course, you would have to pick the start date and then apply the pattern to determine correct occurences. However I was thinking of it more like a “convenience” function:

I supply a date on / after which I’m interested in the next occurence. Internally the class could then do the pattern calculation and stop if it hits a date / time on / after the supplied date. If there isn’t any occurence being calculated for dates on / after the supplied date, DateTime.MinValue would be returned.

Hope this makes sense

Kai

A suggestion for iCalender users who want to create their own "NextDate" function:

Call GenerateOccurrences(DateTime.Now, dateEndRange) within a loop in which you offset dateEndRange with a successively larger "frequency", e.g. dateEndRange = Now.AddHours(1), then dateEndRange = Now.AddDays(1)... until the resulting DateCollection.Count is > 0. Return the first date in that collection.

Brute force method, but lets you avoid generating & storing huge date collections when you just care about the next date.

(Any comments, Roman?)

--Tom

I disagree that it's "computationally impossible" to determine the next occurrence of a pattern. If I give you a "from" date and a count, it should be possible to get the next X occurrences very easily. Just process as if the date range were specified from the "from" date until MaxDate, and stop when X number of occurrences have been found.

This is actually important to me, and one of the reasons I'm looking at your component in the first place. I need an RRule evaluation algorithm or package to do exactly this.

Since I'm here, I may as well ask my other question. I have a licensing question. At most, my current project will have two developers that actually need to touch the calendaring functions at all. But there are 12 other developers that will need to have the library installed so that they can build. We don't need everyone to be actively developing with the library, so the site license seems excessive. We just need them to be able to work on their parts of the project. Does your licensing allow for this?

Hi,

Currently we do not have any immediate plans to implement this feature in the near future.
Sorry for the inconvenience.

MelGrubb:

I have a licensing question. At most, my current project will have two developers that actually need to touch the calendaring functions at all. But there are 12 other developers that will need to have the library installed so that they can build. We don't need everyone to be actively developing with the library, so the site license seems excessive. We just need them to be able to work on their parts of the project. Does your licensing allow for this?

Dear Mel,

For sales inquiries, we use Aspose.Purchase forum. I have created an inquiry in Aspose.Purchase forum on your behalf and answered it. You may access it using this URL, http://www.aspose.com/community/forums/thread/121106.aspx

Have a good time.