Commit e5739a69 authored by Barry Warsaw's avatar Barry Warsaw

formatdate(): Jason Mastaler correctly points out that divmod with a

negative modulus won't return the right values.  So always do positive
modulus on an absolute value and twiddle the sign as appropriate after
the fact.
parent 75a40fcc
...@@ -130,8 +130,14 @@ def formatdate(timeval=None, localtime=0): ...@@ -130,8 +130,14 @@ def formatdate(timeval=None, localtime=0):
offset = time.altzone offset = time.altzone
else: else:
offset = time.timezone offset = time.timezone
hours, minutes = divmod(offset, -3600) hours, minutes = divmod(abs(offset), 3600)
zone = '%+03d%02d' % (hours, minutes / -60) # Remember offset is in seconds west of UTC, but the timezone is in
# minutes east of UTC, so the signs differ.
if offset > 0:
sign = '-'
else:
sign = '+'
zone = '%s%02d%02d' % (sign, hours, minutes / 60)
else: else:
now = time.gmtime(timeval) now = time.gmtime(timeval)
# Timezone offset is always -0000 # Timezone offset is always -0000
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment