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_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_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_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. 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_stamp(self): timestamp = self._get_attr('stamp') return xep_0082.parse('%sZ' % timestamp)
def get_end(self): timestamp = self._get_sub_text('end') return xep_0082.parse(timestamp)
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_rev(self): if not self.xml.text: return None return xep_0082.parse(self.xml.text)
def get_expiry(self): expiry = self._get_attr('expiry') if expiry.lower() == 'presence': return expiry return xep_0082.parse(expiry)
def get_since(self): timestamp = self._get_attr('since') 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_date(self): timestamp = self._get_attr('date') return xep_0082.parse(timestamp)