Example #1
0
 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_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
Example #4
0
 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
Example #6
0
 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
Example #7
0
    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
Example #9
0
 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
Example #10
0
    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
Example #11
0
    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:])
Example #12
0
    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
Example #13
0
    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
Example #14
0
    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)
Example #15
0
    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:])
Example #16
0
    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)
Example #17
0
 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
Example #18
0
 def get_end(self):
     timestamp = self._get_sub_text('end')
     return xep_0082.parse(timestamp)
Example #19
0
 def get_start(self):
     timestamp = self._get_sub_text('start')
     return xep_0082.parse(timestamp)
Example #20
0
 def get_stamp(self):
     timestamp = self._get_attr('stamp')
     return xep_0082.parse(timestamp) if timestamp else None
Example #21
0
 def get_stamp(self):
     timestamp = self._get_attr('stamp')
     return xep_0082.parse(timestamp) if timestamp else None
Example #22
0
 def get_rev(self):
     if not self.xml.text:
         return None
     return xep_0082.parse(self.xml.text)
Example #23
0
 def get_start(self):
     fields = self.__get_fields()
     field = fields.get('start')
     if field:
         return xep_0082.parse(field['value'])
Example #24
0
 def get_end(self) -> Optional[datetime]:
     fields = self.get_fields()
     field = fields.get('end')
     if field:
         return xep_0082.parse(field['value'])
     return None
Example #25
0
 def get_since(self):
     timestamp = self._get_attr('since')
     return xep_0082.parse(timestamp)
Example #26
0
 def get_date(self):
     timestamp = self._get_attr('date')
     return xep_0082.parse(timestamp)
Example #27
0
 def get_expiry(self):
     expiry = self._get_attr('expiry')
     if expiry.lower() == 'presence':
         return expiry
     return xep_0082.parse(expiry)
Example #28
0
 def get_end(self):
     fields = self.__get_fields()
     field = fields.get('end')
     if field:
         return xep_0082.parse(field['value'])