def searchEvents(self, calendarObj, start, end): events = [] # initialize list for events _events = calendarObj.date_search( start=start.astimezone(timezone.utc), end=end.astimezone(timezone.utc) ) # pull events from caldav server, with start and end in utc for e in _events: name = e.vobject_instance.vevent.summary.value.strip() start = e.vobject_instance.vevent.dtstart.value end = e.vobject_instance.vevent.dtend.value if type(start) == type(dt.now()): # if start/end are datetimes start = start.astimezone( default_timezone()) # convert to local TZ end = end.astimezone(default_timezone()) # otherwise, they are dates, and can be left event_dict = { 'name': name, # build dict with event info 'start': start, 'end': end } events.append(event_dict) # add dict to list events.reverse( ) # events return from caldav server in reverse-chrono order return events # so reverse the list to allow mycroft to read them off in order
def test_default_timezone(self, mock_conf): mock_conf.get.return_value = test_config self.assertEqual(default_timezone(), tzfile('/usr/share/zoneinfo/America/Chicago')) # Test missing tz-info mock_conf.get.return_value = {} self.assertEqual(default_timezone(), tzlocal())
def test_extract_timezone(self): """Check that extract_datetime returns the expected timezone.""" default_tz = default_timezone() dt, _ = extract_datetime("today") # As default_timezone() returns tzlocal() and extract_datetime() may # return a tzfile we cannot directly compare dt.tzinfo to default_tz. self.assertEqual(dt, dt.astimezone(default_tz))
def initialize(self): """ Checks if the credentials (url, username and password) are set on Mycroft website. If not, a corresponding dialog will be displayed. If the credentials are present, a CalDavInterface instance is created. :return: [bool] False if credentials are not set """ self.timezone = default_timezone() username = self.settings.get('username') password = self.settings.get('password') url = self.settings.get('url') if not username or not password or not url: self.speak_dialog('err.nextcloud.settings.missing') return False self.caldav_interface = CalDavInterface(url, username, password, self.timezone) self.log.info( f"Initialized CaldDavInterface with timezone {self.timezone}") return True
def test_extract_datetime(self): """Check that extract_datetime returns the expected timezone.""" tz = default_timezone() dt, _ = extract_datetime("today") self.assertEqual(tz, dt.tzinfo)
def get_alarm_local(self, alarm=None, timestamp=None): if timestamp: ts = timestamp else: ts = alarm["timestamp"] return datetime.fromtimestamp(ts, default_timezone())