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

recurring events with multiple "byweekday"s return wrong occurences #231

Open
stratoukos opened this issue Jul 29, 2016 · 4 comments · May be fixed by #232
Open

recurring events with multiple "byweekday"s return wrong occurences #231

stratoukos opened this issue Jul 29, 2016 · 4 comments · May be fixed by #232

Comments

@stratoukos
Copy link

An event with multiple byweekdays (eg weekly every Friday and Saturday) will return less occurrences than it should when calling get_occurrences.

The reason seems to be _event_params since it overrides the rule's params with params derived from the event's start date.

stratoukos pushed a commit to indevgr/django-scheduler that referenced this issue Jul 29, 2016
@stratoukos stratoukos linked a pull request Jul 29, 2016 that will close this issue
stratoukos pushed a commit to indevgr/django-scheduler that referenced this issue Jul 29, 2016
stratoukos pushed a commit to indevgr/django-scheduler that referenced this issue Aug 1, 2016
@mpaolino
Copy link
Contributor

mpaolino commented Jan 5, 2017

@llazzaro Isn't this fixed?

@sinanthottan
Copy link

@stratoukos Can you please help me set rules for Weekly every Thursday and Sunday. I tried setting up params= byweekday:3,5;
but it takes only 3. How can i set multiple days in a week?

@mpaolino
Copy link
Contributor

@sinanthottan this is an usage question, a new ticket would be better, for the sake of minimum organization I'll ignore further comments on this thread. If you're still having issues please specify how you create your event, and your rule, that means the exact code you are using.
BTW here is an complete example made into a test for a event and rule that does what you want:

    def test_weekly_more_than_one_day(self): 
        rule = Rule(frequency = "DAILY", params="byweekday:TH,SA")
        rule.save()
        cal = Calendar(name="MyCalTest")
        cal.save()
        data = {
                'title': 'Something that happens Thursdays and Saturdays at 10 am UTC',
                'start': datetime.datetime(2018, 1, 1, 10, 0, tzinfo=pytz.utc),
                'end': datetime.datetime(2018, 1, 1, 10, 0, tzinfo=pytz.utc),
                'end_recurring_period' : datetime.datetime(2018, 2, 1, 0, 0, tzinfo=pytz.utc),
                'rule': rule,
                'calendar': cal
               }
        recurring_event = Event(**data)
        recurring_event.save()
        period = Period(events=Event.objects.all(),
                        start = datetime.datetime(2018, 1, 1, 0, 0, tzinfo=pytz.utc),
                        end = datetime.datetime(2018, 2, 1, 0, 0, tzinfo=pytz.utc))
        occurrence_list = period.occurrences
        self.assertEqual(["%s to %s" %(o.start, o.end) for o in occurrence_list],
                         ['2018-01-04 10:00:00+00:00 to 2018-01-04 10:00:00+00:00',
                          '2018-01-06 10:00:00+00:00 to 2018-01-06 10:00:00+00:00',
                          '2018-01-11 10:00:00+00:00 to 2018-01-11 10:00:00+00:00',
                          '2018-01-13 10:00:00+00:00 to 2018-01-13 10:00:00+00:00',
                          '2018-01-18 10:00:00+00:00 to 2018-01-18 10:00:00+00:00',
                          '2018-01-20 10:00:00+00:00 to 2018-01-20 10:00:00+00:00',
                          '2018-01-25 10:00:00+00:00 to 2018-01-25 10:00:00+00:00',
                          '2018-01-27 10:00:00+00:00 to 2018-01-27 10:00:00+00:00'])

dvazar added a commit to dvazar/django-scheduler that referenced this issue Feb 19, 2019
@ataylor32
Copy link

I ran into this problem too. The following code creates a recurring event that occurs every Monday, Wednesday, and Friday. I have the event set to have its first occurrence on Monday, May 17, 2021. The code then prints all of the occurrences for the month of May 2021.

import datetime
import pytz
from schedule.models import Calendar, Event, Rule

rule = Rule.objects.create(
    name='Weekly on Monday, Wednesday, Friday',
    description='Weekly on Monday, Wednesday, Friday',
    frequency='WEEKLY',
    params='byweekday:0,2,4',
)

calendar = Calendar.objects.create(
    name='Test',
    slug='test',
)

event = Event.objects.create(
    start=datetime.datetime(2021, 5, 17, 12, tzinfo=pytz.utc),
    end=datetime.datetime(2021, 5, 17, 13, tzinfo=pytz.utc),
    title='Meeting',
    rule=rule,
    calendar=calendar,
)

for occurrence in event.get_occurrences(
    start=datetime.datetime(2021, 5, 1),
    end=datetime.datetime(2021, 5, 31, 23, 59, 59),
):
    print(occurrence)

Expected output (every Monday, Wednesday, and Friday in May 2021 beginning with Monday, May 17th):

May 17, 2021 to May 17, 2021
May 19, 2021 to May 19, 2021
May 21, 2021 to May 21, 2021
May 24, 2021 to May 24, 2021
May 26, 2021 to May 26, 2021
May 28, 2021 to May 28, 2021
May 31, 2021 to May 31, 2021

Actual output (every Monday in May 2021 beginning with Monday, May 17th):

May 17, 2021 to May 17, 2021
May 24, 2021 to May 24, 2021
May 31, 2021 to May 31, 2021

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

Successfully merging a pull request may close this issue.

4 participants