django-recurrence
django-recurrence copied to clipboard
Is there a "include_dtend" parameter?
It seems that sometimes the datetime of dtend
will appear in the recurrence.
Say I want to get all Monday of odd week.
recurrence.Recurrence(
dtstart = datetime.datetime(2021,1,1,0),
dtend = datetime.datetime(2022,1,1,0),
rrules=[recurrence.Rule(recurrence.WEEKLY,interval=2,byday=0 ), ],
include_dtstart=False
).between(datetime.datetime(2021,1,1),datetime.datetime(2022,1,2),inc=False)
The output is:
[datetime.datetime(2021, 1, 11, 0, 0),
datetime.datetime(2021, 1, 25, 0, 0),
...
datetime.datetime(2021, 12, 27, 0, 0),
datetime.datetime(2022, 1, 1, 0, 0)]
The last datetime is Saterday rather than Monday.
I know it can be solved by just setting the dtend
the last recurrence.
But I wonder if there is another way to eliminate the last element.
you can see this problem easier, use a list that produces weekdays:
[a.date().weekday() for a in recurrence.Recurrence(
dtstart = datetime(2021,1,1,0),
dtend = datetime(2022,1,1,0),
rrules=[recurrence.Rule(recurrence.WEEKLY,interval=2,byday=0 ), ],
include_dtstart=False
).between(datetime(2021,1,1),datetime(2022,1,2),inc=False)]
This is also true if you use inc=True
instead of include_dtstart
.
IMHO this is clearly a severe bug, as the pattern "recurrence.Rule(recurrence.WEEKLY,interval=2,byday=0 )" is definitely not meaning exactly what it says. If I want to include the first or last occurrence, it still has to obey the rules, each "second monday". if that's a monday, find, if not, then not.
I find the whole django-recurrence .between()
-API definitely a mess, and IMHO there should be a release that fixes this behaviour and cleans up all the inc/include_dt* things completely.
after
should mean what it says: AFTER that point in time. It would help to add type annotations, so it it clear wether start/end parameters are a date or a datetime object (in fact they are datetime) - which makes it even more complicated. A rule creates date objects, and to compare them to datetimes can be tricky: is datetime(2020,12,1,0,5,0) after date(2020,12,1)? it is per datetime, but it's the same when just comparing the dates, so "after" would be false here.
But please, fix this bug here and don't include first/last occurrences that don't match the given pattern.
@ruiqurm maybe you could change the title to something like "between does not respect rrule pattern".