comparison mercurial/util.py @ 15505:ae04af1ce78d stable

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
author Dmitry Panov <dop@itoolabs.com>
date Sun, 13 Nov 2011 00:29:26 +0000
parents 396e83d635a6
children 646759147717 8f4bad72d8b1
comparison
equal deleted inserted replaced
15499:58f96703a9ab 15505:ae04af1ce78d
14 """ 14 """
15 15
16 from i18n import _ 16 from i18n import _
17 import error, osutil, encoding 17 import error, osutil, encoding
18 import errno, re, shutil, sys, tempfile, traceback 18 import errno, re, shutil, sys, tempfile, traceback
19 import os, time, calendar, textwrap, signal 19 import os, time, datetime, calendar, textwrap, signal
20 import imp, socket, urllib 20 import imp, socket, urllib
21 21
22 if os.name == 'nt': 22 if os.name == 'nt':
23 import windows as platform 23 import windows as platform
24 else: 24 else:
898 if limit: 898 if limit:
899 limit -= len(s) 899 limit -= len(s)
900 yield s 900 yield s
901 901
902 def makedate(): 902 def makedate():
903 lt = time.localtime() 903 ct = time.time()
904 if lt[8] == 1 and time.daylight: 904 if ct < 0:
905 tz = time.altzone
906 else:
907 tz = time.timezone
908 t = time.mktime(lt)
909 if t < 0:
910 hint = _("check your clock") 905 hint = _("check your clock")
911 raise Abort(_("negative timestamp: %d") % t, hint=hint) 906 raise Abort(_("negative timestamp: %d") % ct, hint=hint)
912 return t, tz 907 delta = (datetime.datetime.utcfromtimestamp(ct) -
908 datetime.datetime.fromtimestamp(ct))
909 tz = delta.days * 86400 + delta.seconds
910 return ct, tz
913 911
914 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'): 912 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'):
915 """represent a (unixtime, offset) tuple as a localized time. 913 """represent a (unixtime, offset) tuple as a localized time.
916 unixtime is seconds since the epoch, and offset is the time zone's 914 unixtime is seconds since the epoch, and offset is the time zone's
917 number of seconds away from UTC. if timezone is false, do not 915 number of seconds away from UTC. if timezone is false, do not