def get_utc(self): """ Return the time in UTC as a datetime object. """ value = self._get_sub_text('utc') if value == '': return xep_0082.parse(xep_0082.datetime()) return xep_0082.parse('%sZ' % value)
def get_rev(self): if not self.xml.text: return None try: return xep_0082.parse(self.xml.text) except ValueError: return self.xml.text
def get_tz(self): if not self.xml.text: return xep_0082.tzutc() try: time = xep_0082.parse('00:00:00%s' % self.xml.text) return time.tzinfo except ValueError: return self.xml.text
def get_timestamp(self) -> Optional[datetime]: """Get the timestamp. :returns: The timestamp. """ stamp = self.xml.attrib.get('timestamp', None) if stamp is not None: return xep_0082.parse(stamp) return stamp
def get_tzo(self): """ Return the timezone offset from UTC as a tzinfo object. """ tzo = self._get_sub_text('tzo') if tzo == '': tzo = 'Z' time = xep_0082.parse('00:00:00%s' % tzo) return time.tzinfo
def set_timestamp(self, value: Union[datetime, str]): """Set the timestamp. :param value: Value of the timestamp (either a datetime or a XEP-0082 timestamp string. """ if isinstance(value, str): value = xep_0082.parse(value) value = xep_0082.format_datetime(value) self.xml.attrib['timestamp'] = value
def set_tzo(self, value): """ Set the timezone offset from UTC. :param value: Either a tzinfo object or the number of seconds (positive or negative) to offset. """ time = xep_0082.time(offset=value) if xep_0082.parse(time).tzinfo == tzutc(): self._set_sub_text('tzo', 'Z') else: self._set_sub_text('tzo', time[-6:])
def set_time(self, value): """ Set both the UTC and TZO fields given a time object. :param value: A datetime object or properly formatted string equivalent. """ date = value if not isinstance(value, dt.datetime): date = xep_0082.parse(value) self['utc'] = date self['tzo'] = date.tzinfo
def set_time(self, value): """ Set both the UTC and TZO fields given a time object. Arguments: value -- A datetime object or properly formatted string equivalent. """ date = value if not isinstance(value, dt.datetime): date = xep_0082.parse(value) self['utc'] = date self['tzo'] = date.tzinfo
def set_utc(self, value): """ Set the time in UTC. :param value: A datetime object or properly formatted string equivalent. """ date = value if not isinstance(value, dt.datetime): date = xep_0082.parse(value) date = date.astimezone(tzutc()) value = xep_0082.format_datetime(date) self._set_sub_text('utc', value)
def set_tzo(self, value): """ Set the timezone offset from UTC. Arguments: value -- Either a tzinfo object or the number of seconds (positive or negative) to offset. """ time = xep_0082.time(offset=value) if xep_0082.parse(time).tzinfo == tzutc(): self._set_sub_text('tzo', 'Z') else: self._set_sub_text('tzo', time[-6:])
def set_utc(self, value): """ Set the time in UTC. Arguments: value -- A datetime object or properly formatted string equivalent. """ date = value if not isinstance(value, dt.datetime): date = xep_0082.parse(value) date = date.astimezone(tzutc()) value = xep_0082.format_datetime(date)[:-1] self._set_sub_text('utc', value)
def get_tz(self): if not self.xml.text: return xep_0082.tzutc() time = xep_0082.parse('00:00:00%s' % self.xml.text) return time.tzinfo
def get_end(self): timestamp = self._get_sub_text('end') return xep_0082.parse(timestamp)
def get_start(self): timestamp = self._get_sub_text('start') return xep_0082.parse(timestamp)
def get_stamp(self): timestamp = self._get_attr('stamp') return xep_0082.parse(timestamp) if timestamp else None
def get_rev(self): if not self.xml.text: return None return xep_0082.parse(self.xml.text)
def get_start(self): fields = self.__get_fields() field = fields.get('start') if field: return xep_0082.parse(field['value'])
def get_end(self) -> Optional[datetime]: fields = self.get_fields() field = fields.get('end') if field: return xep_0082.parse(field['value']) return None
def get_since(self): timestamp = self._get_attr('since') return xep_0082.parse(timestamp)
def get_date(self): timestamp = self._get_attr('date') return xep_0082.parse(timestamp)
def get_expiry(self): expiry = self._get_attr('expiry') if expiry.lower() == 'presence': return expiry return xep_0082.parse(expiry)
def get_end(self): fields = self.__get_fields() field = fields.get('end') if field: return xep_0082.parse(field['value'])