@@ -179,7 +179,7 @@ def _format_time(hh, mm, ss, us, timespec='auto'):
179
179
else :
180
180
return fmt .format (hh , mm , ss , us )
181
181
182
- def _format_offset (off ):
182
+ def _format_offset (off , sep = ':' ):
183
183
s = ''
184
184
if off is not None :
185
185
if off .days < 0 :
@@ -189,9 +189,9 @@ def _format_offset(off):
189
189
sign = "+"
190
190
hh , mm = divmod (off , timedelta (hours = 1 ))
191
191
mm , ss = divmod (mm , timedelta (minutes = 1 ))
192
- s += "%s%02d:% 02d" % (sign , hh , mm )
192
+ s += "%s%02d%s% 02d" % (sign , hh , sep , mm )
193
193
if ss or ss .microseconds :
194
- s += ":% 02d" % ss .seconds
194
+ s += "%s% 02d" % ( sep , ss .seconds )
195
195
196
196
if ss .microseconds :
197
197
s += '.%06d' % ss .microseconds
@@ -222,24 +222,10 @@ def _wrap_strftime(object, format, timetuple):
222
222
newformat .append (freplace )
223
223
elif ch == 'z' :
224
224
if zreplace is None :
225
- zreplace = ""
226
225
if hasattr (object , "utcoffset" ):
227
- offset = object .utcoffset ()
228
- if offset is not None :
229
- sign = '+'
230
- if offset .days < 0 :
231
- offset = - offset
232
- sign = '-'
233
- h , rest = divmod (offset , timedelta (hours = 1 ))
234
- m , rest = divmod (rest , timedelta (minutes = 1 ))
235
- s = rest .seconds
236
- u = offset .microseconds
237
- if u :
238
- zreplace = '%c%02d%02d%02d.%06d' % (sign , h , m , s , u )
239
- elif s :
240
- zreplace = '%c%02d%02d%02d' % (sign , h , m , s )
241
- else :
242
- zreplace = '%c%02d%02d' % (sign , h , m )
226
+ zreplace = _format_offset (object .utcoffset (), sep = "" )
227
+ else :
228
+ zreplace = ""
243
229
assert '%' not in zreplace
244
230
newformat .append (zreplace )
245
231
elif ch == 'Z' :
0 commit comments