You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code creates a recurring event that usually occurs on Monday, but there are five instances where it occurs on Tuesday instead. When daylight saving time is involved, some of the events that should have been moved to Tuesday appear to have been copied to Tuesday instead (i.e. the Monday occurrence is still appearing in addition to the Tuesday occurrence).
importdatetimeimportpytzfromschedule.modelsimportCalendar, Event, Occurrence, Rulefromschedule.viewsimport_api_occurrencesrule=Rule.objects.create(
name='Weekly',
description='Weekly',
frequency='WEEKLY',
)
calendar=Calendar.objects.create(
name='Test',
slug='test',
)
event=Event.objects.create(
start=datetime.datetime(2021, 1, 4, 12, tzinfo=pytz.utc),
end=datetime.datetime(2021, 1, 4, 13, tzinfo=pytz.utc),
title='Weekly Meeting',
rule=rule,
calendar=calendar,
)
fordatein (
'2021-01-18',
'2021-05-31',
'2021-07-05',
'2021-09-06',
'2021-12-27',
):
mon=datetime.date(*map(int, date.split('-')))
tue=mon+datetime.timedelta(days=1)
mon_values= {'year': mon.year, 'month': mon.month, 'day': mon.day}
tue_values= {'year': tue.year, 'month': tue.month, 'day': tue.day}
Occurrence.objects.create(
event=event,
start=event.start.replace(**tue_values),
end=event.end.replace(**tue_values),
original_start=event.start.replace(**mon_values),
original_end=event.end.replace(**mon_values),
)
# The following code works correctlyforoccurrenceinevent.get_occurrences(
start=datetime.datetime(2021, 1, 1, tzinfo=pytz.utc),
end=datetime.datetime(2021, 12, 31, 23, 59, 59, tzinfo=pytz.utc),
):
print(occurrence.start.strftime('%a, %b %-d, %Y'))
# The following code includes these dates in its output:## Mon, May 31, 2021# Mon, Jul 5, 2021# Mon, Sep 6, 2021## This behavior is incorrect and it is happening because of DST. If you# change the `timezone` kwarg to `'America/Phoenix'` then it works.foroccurrencein_api_occurrences(
start='2021-01-01T00:00:00',
end='2021-12-31T23:59:59',
calendar_slug='test',
timezone='America/New_York',
):
print(occurrence['start'].strftime('%a, %b %-d, %Y'))
The text was updated successfully, but these errors were encountered:
The following code creates a recurring event that usually occurs on Monday, but there are five instances where it occurs on Tuesday instead. When daylight saving time is involved, some of the events that should have been moved to Tuesday appear to have been copied to Tuesday instead (i.e. the Monday occurrence is still appearing in addition to the Tuesday occurrence).
The text was updated successfully, but these errors were encountered: