-
Notifications
You must be signed in to change notification settings - Fork 393
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
Comments
@llazzaro Isn't this fixed? |
@stratoukos Can you please help me set rules for Weekly every Thursday and Sunday. I tried setting up params= byweekday:3,5; |
@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. 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']) |
…n original repo)
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):
Actual output (every Monday in May 2021 beginning with Monday, May 17th):
|
An event with multiple
byweekday
s (eg weekly every Friday and Saturday) will return less occurrences than it should when callingget_occurrences
.The reason seems to be
_event_params
since it overrides the rule's params with params derived from the event'sstart
date.The text was updated successfully, but these errors were encountered: