Philipp Hörist pushed to branch master at gajim / gajim
Commits: 5d853e90 by André Apitzsch at 2018-08-19T21:29:05Z Time: use classes from standard library
- - - - -
1 changed file:
- gajim/common/modules/entity_time.py
Changes:
===================================== gajim/common/modules/entity_time.py ===================================== --- a/gajim/common/modules/entity_time.py +++ b/gajim/common/modules/entity_time.py @@ -25,8 +25,6 @@ from gajim.common.nec import NetworkIncomingEvent
log = logging.getLogger('gajim.c.m.entity_time')
-ZERO = datetime.timedelta(0) -
class EntityTime: def __init__(self, con): @@ -79,7 +77,7 @@ class EntityTime: tzo = '0:0' try: tzoh, tzom = tzo.split(':') - except Exception as e: + except Exception: log.warning('Wrong tzo node: %s', stanza) return utc_time = time_.getTag('utc').getData() @@ -106,8 +104,11 @@ class EntityTime: e, stanza.getFrom()) return
- t = t.replace(tzinfo=UTC()) - return t.astimezone(contact_tz(tzoh, tzom)).strftime('%c') + utc = datetime.timezone(datetime.timedelta(0)) + t = t.replace(tzinfo=utc) + utc_offset = datetime.timedelta(hours=int(tzoh), minutes=int(tzom)) + contact_tz = datetime.timezone(utc_offset, "remote timezone") + return t.astimezone(contact_tz).strftime('%c')
def _answer_request(self, con, stanza): log.info('%s asked for the time', stanza.getFrom()) @@ -138,33 +139,5 @@ class TimeResultReceivedEvent(NetworkIncomingEvent): return True
-class UTC(datetime.tzinfo): - def utcoffset(self, dt): - return ZERO - - def tzname(self, dt): - return "UTC" - - def dst(self, dt): - return ZERO - - -class contact_tz(datetime.tzinfo): - - def __init__(self, tzoh, tzom): - self._tzoh = tzoh - self._tzom = tzom - - def utcoffset(self, dt): - return datetime.timedelta(hours=int(self._tzoh), - minutes=int(self._tzom)) - - def tzname(self, dt): - return "remote timezone" - - def dst(self, dt): - return ZERO - - def get_instance(*args, **kwargs): return EntityTime(*args, **kwargs), 'EntityTime'
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/5d853e902a0506f88393b1e8a4ab16a971c...