import datetime as dt import re, logging from .sync import Event class IcalHelper: _WEEKDAY_MAP = { 'Mon': 0, 'Tue': 1, 'Wed': 2, 'Thu': 3, 'Fri': 4, 'Sat': 5, 'Sun': 6 } def __init__(self): self._l = logging.getLogger(__name__) self.dDay = dt.timedelta(days=1) self.firstDay = dt.datetime(year=dt.datetime.now().year, month=1, day=1) self.reTime = re.compile(r'(\d{1,2}):(\d{2})') def getStart(self, event: Event, holidays): self._getFirstWeekdayInYear(event.day) self._getFirstOccurence(event, holidays) pass def _getFirstWeekdayInYear(self, weekday): candidate = self.firstDay while candidate.weekday() != self._WEEKDAY_MAP[weekday]: candidate += self.dDay self._l.log(5, 'First %s in year is %s', weekday, candidate) return candidate def _getSortedHolidays(self, holidays): return sorted(holidays['holidays'], key=lambda h: h['from']) def _getSortedFeasts(self, holidays): return sorted(holidays['feasts']) def _getFirstOccurence(self, event: Event, holidays): firstWeekday = self._getFirstWeekdayInYear(event.day) firstWeekday.tzinfo = dt.timezone.tzname('Europe/Berlin')