I have an rrule instance e.g.
r = rrule(WEEKLY, byweekday=SA, count=10, dtstart=parse('20081001'))
where dtstart and byweekday may change.
If I then want to generate the ten dates that follow on from this rrule, what’s the best way of doing it? Can I assign a new value to the _dtstart member of r? That seems to work but I’m not sure.
e.g.
r._dtstart = list(r)[-1] or something like that
Otherwise I guess I’ll create a new rrule and access _dtstart, _count, _byweekday etc. of the original instance.
EDIT:
I’ve thought about it more, and I think what I should be doing is omitting the ‘count’ argument when I create the first rrule instance. I can still get ten occurrences the first time I use the rrule
instances = list(r[0:10])
and then afterwards I can get more
more = list(r[10:20])
I think that solves my problem without any ugliness
Firstly,
r._dtstart = list(r)[-1]will give you the last date in the original sequence of dates. If you use that, without modification, for the beginning of a new sequence, you will end up with a duplicate date, i.e. the last date of the first sequence will be the same as the first date of the new sequence, which is probably not what you want:Furthermore, it is considered poor form to manipulate r._dtstart as it is clearly intended to be a private attribute.
Instead, do something like this:
This codes does not access any private attributes of rrule (although you might have to look at
_byweekday).