| ... |
... |
@@ -25,8 +25,6 @@ from gajim.common.nec import NetworkIncomingEvent |
|
25
|
25
|
|
|
26
|
26
|
log = logging.getLogger('gajim.c.m.entity_time')
|
|
27
|
27
|
|
|
28
|
|
-ZERO = datetime.timedelta(0)
|
|
29
|
|
-
|
|
30
|
28
|
|
|
31
|
29
|
class EntityTime:
|
|
32
|
30
|
def __init__(self, con):
|
| ... |
... |
@@ -79,7 +77,7 @@ class EntityTime: |
|
79
|
77
|
tzo = '0:0'
|
|
80
|
78
|
try:
|
|
81
|
79
|
tzoh, tzom = tzo.split(':')
|
|
82
|
|
- except Exception as e:
|
|
|
80
|
+ except Exception:
|
|
83
|
81
|
log.warning('Wrong tzo node: %s', stanza)
|
|
84
|
82
|
return
|
|
85
|
83
|
utc_time = time_.getTag('utc').getData()
|
| ... |
... |
@@ -106,8 +104,11 @@ class EntityTime: |
|
106
|
104
|
e, stanza.getFrom())
|
|
107
|
105
|
return
|
|
108
|
106
|
|
|
109
|
|
- t = t.replace(tzinfo=UTC())
|
|
110
|
|
- return t.astimezone(contact_tz(tzoh, tzom)).strftime('%c')
|
|
|
107
|
+ utc = datetime.timezone(datetime.timedelta(0))
|
|
|
108
|
+ t = t.replace(tzinfo=utc)
|
|
|
109
|
+ utc_offset = datetime.timedelta(hours=int(tzoh), minutes=int(tzom))
|
|
|
110
|
+ contact_tz = datetime.timezone(utc_offset, "remote timezone")
|
|
|
111
|
+ return t.astimezone(contact_tz).strftime('%c')
|
|
111
|
112
|
|
|
112
|
113
|
def _answer_request(self, con, stanza):
|
|
113
|
114
|
log.info('%s asked for the time', stanza.getFrom())
|
| ... |
... |
@@ -138,33 +139,5 @@ class TimeResultReceivedEvent(NetworkIncomingEvent): |
|
138
|
139
|
return True
|
|
139
|
140
|
|
|
140
|
141
|
|
|
141
|
|
-class UTC(datetime.tzinfo):
|
|
142
|
|
- def utcoffset(self, dt):
|
|
143
|
|
- return ZERO
|
|
144
|
|
-
|
|
145
|
|
- def tzname(self, dt):
|
|
146
|
|
- return "UTC"
|
|
147
|
|
-
|
|
148
|
|
- def dst(self, dt):
|
|
149
|
|
- return ZERO
|
|
150
|
|
-
|
|
151
|
|
-
|
|
152
|
|
-class contact_tz(datetime.tzinfo):
|
|
153
|
|
-
|
|
154
|
|
- def __init__(self, tzoh, tzom):
|
|
155
|
|
- self._tzoh = tzoh
|
|
156
|
|
- self._tzom = tzom
|
|
157
|
|
-
|
|
158
|
|
- def utcoffset(self, dt):
|
|
159
|
|
- return datetime.timedelta(hours=int(self._tzoh),
|
|
160
|
|
- minutes=int(self._tzom))
|
|
161
|
|
-
|
|
162
|
|
- def tzname(self, dt):
|
|
163
|
|
- return "remote timezone"
|
|
164
|
|
-
|
|
165
|
|
- def dst(self, dt):
|
|
166
|
|
- return ZERO
|
|
167
|
|
-
|
|
168
|
|
-
|
|
169
|
142
|
def get_instance(*args, **kwargs):
|
|
170
|
143
|
return EntityTime(*args, **kwargs), 'EntityTime'
|