How to use the icalendar.vRecur function in icalendar

To help you get started, we’ve selected a few icalendar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / khal / tests / ui / test_editor.py View on Github external
def test_check_understood_rrule():
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=1SU')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYMONTHDAY=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
    )
github pimutils / khal / tests / ui / test_editor.py View on Github external
icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=1SU')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYMONTHDAY=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TU,TH;BYSETPOS=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYSETPOS=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,SU,MO,TH,FR,TU,SA;BYSETPOS=1')
    )
    assert RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;INTERVAL=2;BYDAY=WE,MO,TH,FR,TU,SA;BYSETPOS=1')
    )
    assert not RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=-1SU')
    )
    assert not RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=1,2,3,4,5,6,7')
    )
    assert not RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYMONTHDAY=-1')
    )
    assert not RecurrenceEditor.check_understood_rrule(
        icalendar.vRecur.from_ical('FREQ=MONTHLY;BYDAY=TH;BYSETPOS=3')
    )
github securestate / king-phisher / tests / ics.py View on Github external
def test_parse_tz_posix_env_var_australia_melbourne(self):
		expected = ics.TimezoneOffsetDetails(
			offset=datetime.timedelta(0, 36000),
			offset_dst=datetime.timedelta(0, 32400),
			dst_start=icalendar.vRecur({
				'BYMONTH': '10',
				'FREQ': 'YEARLY',
				'INTERVAL': 1,
				'BYDAY': '1SU'
			}),
			dst_end=icalendar.vRecur({
				'BYMONTH': '4',
				'FREQ': 'YEARLY',
				'INTERVAL': 1,
				'BYDAY': '1SU'
			})
		)
		self.assertParsedTimezoneOffsetDetailsMatch('Australia/Melbourne', expected)
github securestate / king-phisher / tests / ics.py View on Github external
def test_parse_tz_posix_env_var_america_new_york(self):
		expected = ics.TimezoneOffsetDetails(
			offset=datetime.timedelta(-1, 68400),
			offset_dst=datetime.timedelta(-1, 64800),
			dst_start=icalendar.vRecur({
				'BYMONTH': '3',
				'FREQ': 'YEARLY',
				'INTERVAL': 1,
				'BYDAY': '2SU'
			}),
			dst_end=icalendar.vRecur({
				'BYMONTH': '11',
				'FREQ': 'YEARLY',
				'INTERVAL': 1,
				'BYDAY': '1SU'
			})
		)
		self.assertParsedTimezoneOffsetDetailsMatch('America/New_York', expected)
github securestate / king-phisher / tests / ics.py View on Github external
def test_parse_tz_posix_env_var_australia_melbourne(self):
		expected = ics.TimezoneOffsetDetails(
			offset=datetime.timedelta(0, 36000),
			offset_dst=datetime.timedelta(0, 32400),
			dst_start=icalendar.vRecur({
				'BYMONTH': '10',
				'FREQ': 'YEARLY',
				'INTERVAL': 1,
				'BYDAY': '1SU'
			}),
			dst_end=icalendar.vRecur({
				'BYMONTH': '4',
				'FREQ': 'YEARLY',
				'INTERVAL': 1,
				'BYDAY': '1SU'
			})
		)
		self.assertParsedTimezoneOffsetDetailsMatch('Australia/Melbourne', expected)
github superdesk / superdesk-planning / server / planning / feed_parsers / ics_2_0.py View on Github external
dates_end = \
                                (datetime.datetime.combine(dtend, datetime.datetime.max.time()) -
                                 datetime.timedelta(days=1)).replace(microsecond=0)
                        if not dates_end.tzinfo:
                            dates_end = local_to_utc(config.DEFAULT_TIMEZONE, dates_end)
                    except AttributeError:
                        dates_end = None
                    item['dates'] = {
                        'start': dates_start,
                        'end': dates_end,
                        'tz': ''
                    }
                    # parse ics RRULE to fit eventsML recurring_rule
                    r_rule = component.get('rrule')
                    if isinstance(r_rule, vRecur):
                        r_rule_dict = vRecur.from_ical(r_rule)
                        if 'FREQ' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['frequency'] = ''.join(
                                r_rule_dict.get('FREQ'))
                        if 'INTERVAL' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['interval'] = r_rule_dict.get('INTERVAL')[0]
                        if 'UNTIL' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['until'] = r_rule_dict.get('UNTIL')[0]
                        if 'COUNT' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['count'] = r_rule_dict.get('COUNT')
                        if 'BYMONTH' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['bymonth'] = ' '.join(
                                r_rule_dict.get('BYMONTH'))
                        if 'BYDAY' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['byday'] = ' '.join(r_rule_dict.get('BYDAY'))
                        if 'BYHOUR' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['byhour'] = ' '.join(
github superdesk / superdesk-planning / server / planning / feed_parsers / ics_2_0.py View on Github external
else:  # Date only is non inclusive
                            dates_end = \
                                (datetime.datetime.combine(dtend, datetime.datetime.max.time()) -
                                 datetime.timedelta(days=1)).replace(microsecond=0)
                        if not dates_end.tzinfo:
                            dates_end = local_to_utc(config.DEFAULT_TIMEZONE, dates_end)
                    except AttributeError:
                        dates_end = None
                    item['dates'] = {
                        'start': dates_start,
                        'end': dates_end,
                        'tz': ''
                    }
                    # parse ics RRULE to fit eventsML recurring_rule
                    r_rule = component.get('rrule')
                    if isinstance(r_rule, vRecur):
                        r_rule_dict = vRecur.from_ical(r_rule)
                        if 'FREQ' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['frequency'] = ''.join(
                                r_rule_dict.get('FREQ'))
                        if 'INTERVAL' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['interval'] = r_rule_dict.get('INTERVAL')[0]
                        if 'UNTIL' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['until'] = r_rule_dict.get('UNTIL')[0]
                        if 'COUNT' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['count'] = r_rule_dict.get('COUNT')
                        if 'BYMONTH' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['bymonth'] = ' '.join(
                                r_rule_dict.get('BYMONTH'))
                        if 'BYDAY' in r_rule_dict.keys():
                            item['dates'].setdefault('recurring_rule', {})['byday'] = ' '.join(r_rule_dict.get('BYDAY'))
                        if 'BYHOUR' in r_rule_dict.keys():
github securestate / king-phisher / king_phisher / ics.py View on Github external
dst_end = None
	match = POSIX_VAR.match(posix_env_var)
	if match:
		match = match.groupdict()
		dst_start = match['start']
		dst_end = match['end']

		match = POSIX_VAR_DST_RRULE.match(dst_start)
		details = match.groupdict()
		byday = details['week'] + DAY_ABBREVIATIONS[int(details['day'])]
		dst_start = icalendar.vRecur({'BYMONTH': details['month'], 'FREQ': 'YEARLY', 'INTERVAL': 1, 'BYDAY': byday})

		match = POSIX_VAR_DST_RRULE.match(dst_end)
		details = match.groupdict()
		byday = details['week'] + DAY_ABBREVIATIONS[int(details['day'])]
		dst_end = icalendar.vRecur({'BYMONTH': details['month'], 'FREQ': 'YEARLY', 'INTERVAL': 1, 'BYDAY': byday})
	else:
		# remove the dst offset if not rrule is present on when it's active
		offset_dst = None
	details = TimezoneOffsetDetails(offset, offset_dst, dst_start, dst_end)
	return details
github securestate / king-phisher / king_phisher / ics.py View on Github external
offset_dst = get_timedelta_for_offset(match['offset_dst'])
	else:
		# default to an hour difference if it's not specified
		offset_dst = offset - datetime.timedelta(0, SECONDS_IN_ONE_HOUR)
	dst_start = None
	dst_end = None
	match = POSIX_VAR.match(posix_env_var)
	if match:
		match = match.groupdict()
		dst_start = match['start']
		dst_end = match['end']

		match = POSIX_VAR_DST_RRULE.match(dst_start)
		details = match.groupdict()
		byday = details['week'] + DAY_ABBREVIATIONS[int(details['day'])]
		dst_start = icalendar.vRecur({'BYMONTH': details['month'], 'FREQ': 'YEARLY', 'INTERVAL': 1, 'BYDAY': byday})

		match = POSIX_VAR_DST_RRULE.match(dst_end)
		details = match.groupdict()
		byday = details['week'] + DAY_ABBREVIATIONS[int(details['day'])]
		dst_end = icalendar.vRecur({'BYMONTH': details['month'], 'FREQ': 'YEARLY', 'INTERVAL': 1, 'BYDAY': byday})
	else:
		# remove the dst offset if not rrule is present on when it's active
		offset_dst = None
	details = TimezoneOffsetDetails(offset, offset_dst, dst_start, dst_end)
	return details