[PATCH] wrong timezone offset if DST rules changed this year (issue2511)
Dmitry Panov
dop at itoolabs.com
Sat Nov 12 18:33:12 CST 2011
# HG changeset patch
# User Dmitry Panov <dop at itoolabs.com>
# Date 1321144166 0
# Node ID ca83bd6d909c1ad6b325262ad008c9567e83b036
# Parent 1bb0a5b02da9ef3505bfb4ac02b2d51cf220220f
makedate: wrong timezone offset if DST rules changed this year (issue2511)
Python's time module sets timezone and altzone based on UTC offsets of
two dates: first and middle day of the current year. This approach doesn't
work on a year when DST rules change.
For example Russia abandoned winter time this year, so the correct UTC
offset
should be +4 now, but time.timezone returns 3 hours difference because
that's
what it was on 01.01.2011.
Related python issue: http://bugs.python.org/issue1647654
diff -r 1bb0a5b02da9 -r ca83bd6d909c mercurial/util.py
--- a/mercurial/util.py Thu Nov 10 17:06:30 2011 -0600
+++ b/mercurial/util.py Sun Nov 13 00:29:26 2011 +0000
@@ -16,7 +16,7 @@
from i18n import _
import error, osutil, encoding
import errno, re, shutil, sys, tempfile, traceback
-import os, time, calendar, textwrap, signal
+import os, time, datetime, calendar, textwrap, signal
import imp, socket, urllib
if os.name == 'nt':
@@ -899,16 +899,14 @@
yield s
def makedate():
- lt = time.localtime()
- if lt[8] == 1 and time.daylight:
- tz = time.altzone
- else:
- tz = time.timezone
- t = time.mktime(lt)
- if t < 0:
+ ct = time.time()
+ if ct < 0:
hint = _("check your clock")
- raise Abort(_("negative timestamp: %d") % t, hint=hint)
- return t, tz
+ raise Abort(_("negative timestamp: %d") % ct, hint=hint)
+ delta = datetime.datetime.utcfromtimestamp(ct) - \
+ datetime.datetime.fromtimestamp(ct)
+ tz = delta.days * 86400 + delta.seconds
+ return ct, tz
def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'):
"""represent a (unixtime, offset) tuple as a localized time.
--
Best regards,
Dmitry Panov
Chief Technology Officer
Itoolabs.
More information about the Mercurial-devel
mailing list