def test_inflate_across_DST(db, default_account, calendar): # If we inflate a RRULE that covers a change to/from Daylight Savings Time, # adjust the base time accordingly to account for the new UTC offset. # Daylight Savings for US/PST: March 8, 2015 - Nov 1, 2015 dst_rrule = ["RRULE:FREQ=WEEKLY;BYDAY=TU"] dst_event = recurring_event(db, default_account, calendar, dst_rrule, start=arrow.get(2015, 03, 03, 03, 03, 03), end=arrow.get(2015, 03, 03, 04, 03, 03)) g = get_start_times(dst_event, end=arrow.get(2015, 03, 21)) # In order for this event to occur at the same local time, the recurrence # rule should be expanded to 03:03:03 before March 8, and 02:03:03 after, # keeping the local time of the event consistent at 19:03. # This is consistent with how Google returns recurring event instances. local_tz = tz.gettz(dst_event.start_timezone) for time in g: if time < arrow.get(2015, 3, 8): assert time.hour == 3 else: assert time.hour == 2 # Test that localizing these times is consistent assert time.astimezone(local_tz).hour == 19 # Test an event that starts during local daylight savings time dst_event = recurring_event(db, default_account, calendar, dst_rrule, start=arrow.get(2015, 10, 27, 02, 03, 03), end=arrow.get(2015, 10, 27, 03, 03, 03)) g = get_start_times(dst_event, end=arrow.get(2015, 11, 11)) for time in g: if time > arrow.get(2015, 11, 1): assert time.hour == 3 else: assert time.hour == 2 assert time.astimezone(local_tz).hour == 19
def test_rrule_parsing(db, default_account, calendar): # This test event starts on Aug 7 and recurs every Thursday at 20:30 # until Sept 18. # There should be 7 total occurrences including Aug 7 and Sept 18. event = recurring_event(db, default_account, calendar, TEST_RRULE) g = get_start_times(event) assert len(g) == 7 # Check we can supply an end date to cut off recurrence expansion g = get_start_times(event, end=arrow.get(2014, 9, 12, 21, 30, 00)) assert len(g) == 6
def test_rrule_exceptions(db, default_account, calendar): # This test event starts on Aug 7 and recurs every Thursday at 20:30 # until Sept 18, except on September 4. event = recurring_event(db, default_account, calendar, TEST_EXDATE_RULE) g = get_start_times(event) assert len(g) == 6 assert arrow.get(2014, 9, 4, 13, 30, 00) not in g
def test_all_day_rrule_parsing(db, default_account, calendar): event = recurring_event(db, default_account, calendar, ALL_DAY_RRULE, start=arrow.get(2014, 8, 7), end=arrow.get(2014, 8, 7), all_day=True) g = get_start_times(event) assert len(g) == 6
def inflate(self, start=None, end=None): # Convert a RecurringEvent into a series of InflatedEvents # by expanding its RRULE into a series of start times. from inbox.events.recurring import get_start_times occurrences = get_start_times(self, start, end) return [InflatedEvent(self, o) for o in occurrences]
def test_inflate_across_DST(db, default_account, calendar): # If we inflate a RRULE that covers a change to/from Daylight Savings Time, # adjust the base time accordingly to account for the new UTC offset. # Daylight Savings for US/PST: March 8, 2015 - Nov 1, 2015 dst_rrule = ["RRULE:FREQ=WEEKLY;BYDAY=TU"] dst_event = recurring_event(db, default_account, calendar, dst_rrule, start=arrow.get(2015, 03, 03, 03, 03, 03), end=arrow.get(2015, 03, 03, 04, 03, 03)) g = get_start_times(dst_event, end=arrow.get(2015, 03, 21))
def test_all_day_rrule_parsing_utc(db, default_account, calendar, rule): # Use an RRULE with timezone away until date + all day event event = recurring_event(db, default_account, calendar, rule, start=arrow.get(2016, 9, 10), end=arrow.get(2016, 9, 13), all_day=True) start_boundary = datetime.datetime(2016, 9, 8, 1, 21, 55) end_boundary = datetime.datetime(2016, 9, 16, 0, 31, 55) g = get_start_times(event, start=start_boundary, end=end_boundary) assert len(g) == 4
# This is consistent with how Google returns recurring event instances. local_tz = tz.gettz(dst_event.start_timezone) for time in g: if time < arrow.get(2015, 3, 8): assert time.hour == 3 else: assert time.hour == 2 # Test that localizing these times is consistent assert time.astimezone(local_tz).hour == 19 # Test an event that starts during local daylight savings time dst_event = recurring_event(db, default_account, calendar, dst_rrule, start=arrow.get(2015, 10, 27, 02, 03, 03), end=arrow.get(2015, 10, 27, 03, 03, 03)) g = get_start_times(dst_event, end=arrow.get(2015, 11, 11)) for time in g: if time > arrow.get(2015, 11, 1): assert time.hour == 3 else: assert time.hour == 2 assert time.astimezone(local_tz).hour == 19 def test_inflate_all_day_event(db, default_account, calendar): event = recurring_event(db, default_account, calendar, ALL_DAY_RRULE, start=arrow.get(2014, 9, 4), end=arrow.get(2014, 9, 4), all_day=True) infl = event.inflate() for i in infl: assert i.all_day