diff options
author | Barry Warsaw <barry@python.org> | 2001-11-19 18:36:43 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-11-19 18:36:43 (GMT) |
commit | e5739a69a755000143849d7f776c4ff2ef8b690a (patch) | |
tree | b7ff9005bb02f12c273ce08b8a36b2db49974222 | |
parent | 75a40fcc3a57c76b3c844706a45a6a3f1a1e4a73 (diff) | |
download | cpython-e5739a69a755000143849d7f776c4ff2ef8b690a.zip cpython-e5739a69a755000143849d7f776c4ff2ef8b690a.tar.gz cpython-e5739a69a755000143849d7f776c4ff2ef8b690a.tar.bz2 |
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.
-rw-r--r-- | Lib/email/Utils.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/email/Utils.py b/Lib/email/Utils.py index 8d46096..b86091b 100644 --- a/Lib/email/Utils.py +++ b/Lib/email/Utils.py @@ -130,8 +130,14 @@ def formatdate(timeval=None, localtime=0): offset = time.altzone else: offset = time.timezone - hours, minutes = divmod(offset, -3600) - zone = '%+03d%02d' % (hours, minutes / -60) + hours, minutes = divmod(abs(offset), 3600) + # 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: now = time.gmtime(timeval) # Timezone offset is always -0000 |