@@ -217,6 +217,40 @@ def __eq__(self, other):
217
217
return self .__dict__ == other .__dict__
218
218
219
219
220
+ try :
221
+ # Class datetime.timezone introduced in Python 3.2
222
+ from datetime import timezone
223
+ del timezone
224
+
225
+ from datetime import datetime
226
+
227
+ def format_local_datetime (dt ):
228
+ """Return a string with local timezone representing the date."""
229
+ return dt .astimezone ().strftime ('%Y-%m-%d %H:%M %z' )
230
+ except ImportError :
231
+ # Python 2 do not have builtin timezone
232
+ import time
233
+ from datetime import datetime
234
+
235
+ def format_local_datetime (dt ):
236
+ """Return a string with local timezone representing the date."""
237
+ def get_timezone_offset ():
238
+ timestamp = time .time ()
239
+ delta = datetime .fromtimestamp (timestamp ) - datetime .utcfromtimestamp (timestamp )
240
+ if delta .seconds >= 0 :
241
+ sign = '+'
242
+ seconds = delta .seconds
243
+ else :
244
+ sign = '-'
245
+ seconds = - delta .seconds
246
+ hours , rest = divmod (seconds , 60 * 60 )
247
+ minutes , _ = divmod (rest , 60 )
248
+ return '%s%02d%02d' % (sign , hours , minutes )
249
+
250
+ offset = get_timezone_offset ()
251
+ return '%s %s' % (dt .strftime ('%Y-%m-%d %H:%M' ), offset )
252
+
253
+
220
254
def invalidate_import_caches ():
221
255
"""Invalidate any import caches that may or may not exist."""
222
256
if importlib and hasattr (importlib , "invalidate_caches" ):
0 commit comments