Closed mattdeluco closed 9 years ago
For the date, you can use exceptions - specifically using the unfortunately undocumented full date or fd
constraint. Only drawback is that it currently isn't supported using the English text parser, but is fully supported by the schedule definition. The idea is that you would end up with something like `every 15 minutes except after 2014-12-31.
{
schedules: [{m: [0,15,30,45]}],
exceptions: [{fd_a: [1420012800000]}]
}
The count is a little trickier, but still doable in the same manner. First, take your base schedule and calculate out the number of desired occurrences. Then just set the last date as the end date like in the previous example.
var schedule = { schedules: [{m: [0,15,30,45]}] };
var next = later.schedule(schedule).next(10);
schedule.exceptions = [{fd_a: [next[next.length-1]}]
I haven't tested this so you may need to muck around with it to get your desired results, but that would be the general idea. If you need to do it with English text strings I would capture the schedule first and then ask for the occurrence count separately.
Does it even make sense to include a count limit as part of the schedule?
Schedules are abstracted from specific dates, aren't they? They don't include start and end dates, for example. So I shouldn't impose any kind of limit until calculating dates using a given schedule, at which point I can pass count as a parameter to later.schedule().next(). At that point I presume "count" dates matching the schedule will be returned starting from the time I called next() (or starting from the date I provide as the second parameter to next()).
I'm asking this as part of my effort to parse RFC 5545 RRULEs (issue #17.) So I think this is a kind of mismatch between later schedules and RRULEs. It seems to me that COUNT and UNTIL should not be included in the later schedule, rather they should be employed by whatever program is using later, and passed to next() when dates are generated from a schedule, as I suggested above. This is problematic though because the whole idea is to abstract the handling of RRULEs into the later library keeping such details hidden from the user.
So now I have a couple thoughts: can I somehow extend later to store COUNT and UNTIL information in a schedule, to be interpreted when later.schedule() is called. The object containing schedules and exceptions could also contain start and end dates, and/or a count. next() could read those values, or have them overwritten with explicit parameters.
Or, perhaps iCal RRULEs have no place in the later library, instead later is a dependency of some other library that parses the rules and uses later to generate dates, as part of a greater whole that implements iCal.
So now I have a couple thoughts: can I somehow extend later to store COUNT and UNTIL information in a schedule, to be interpreted when later.schedule() is called.
Sure, the schedule definition is just a simple map. You can add whatever properties you want on to it and then just update schedule.js
to pull values from the map when calculating schedules.
var schedule = { schedules: [{m: [0,15,30,45]}], count: 10};
Here are the changes that would need to be made to next
for example, pretty minimal since the library already supports counts, start dates, and end dates when calculating future occurrences.
next: function(count, startDate, endDate) {
return getInstances('next', count || sched.count || 1, startDate || sched.startDate, endDate || sched.endDate);
},
Is there a way, or may I request support, to limit recurrences by specifying a date on which the recurrence schedule should end, or by specifying that the recurrence only recur a certain number of times?
For example, "every 15 minutes until 2014-12-31" or "every 15 minutes 10 times".