Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5739a6

Browse files
committed
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.
1 parent 75a40fc commit e5739a6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/email/Utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@ def formatdate(timeval=None, localtime=0):
130130
offset = time.altzone
131131
else:
132132
offset = time.timezone
133-
hours, minutes = divmod(offset, -3600)
134-
zone = '%+03d%02d' % (hours, minutes / -60)
133+
hours, minutes = divmod(abs(offset), 3600)
134+
# Remember offset is in seconds west of UTC, but the timezone is in
135+
# minutes east of UTC, so the signs differ.
136+
if offset > 0:
137+
sign = '-'
138+
else:
139+
sign = '+'
140+
zone = '%s%02d%02d' % (sign, hours, minutes / 60)
135141
else:
136142
now = time.gmtime(timeval)
137143
# Timezone offset is always -0000

0 commit comments

Comments
 (0)