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

Is there a "include_dtend" parameter? #181

Open
ruiqurm opened this issue Feb 15, 2021 · 2 comments
Open

Is there a "include_dtend" parameter? #181

ruiqurm opened this issue Feb 15, 2021 · 2 comments

Comments

@ruiqurm
Copy link

ruiqurm commented Feb 15, 2021

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.

@ruiqurm ruiqurm changed the title Is there has a "include_dtend" parameter? Is there a "include_dtend" parameter? Feb 16, 2021
@nerdoc
Copy link

nerdoc commented Oct 10, 2022

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.

@nerdoc
Copy link

nerdoc commented Oct 10, 2022

@ruiqurm maybe you could change the title to something like "between does not respect rrule pattern".

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

No branches or pull requests

3 participants