# HG changeset patch # User Jose M. Prieto # Date 1159871594 -7200 # Node ID e96d2956eb4adda44bb6a0bd51d08a4873cb7e1d # Parent 1d3aceae87c133488e6cd6c387345ec740dc29d3 util.strdate: compute timestamp using UTC, not local timezone diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -15,7 +15,7 @@ platform-specific details from the core. from i18n import gettext as _ from demandload import * demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile") -demandload(globals(), "os threading time") +demandload(globals(), "os threading time calendar") # used by parsedate defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', @@ -903,14 +903,16 @@ def strdate(string, format='%a %b %d %H: (string[-5] == '+' or string[-5] == '-') and string[-6].isspace()) + # NOTE: unixtime = localunixtime + offset if hastimezone(string): date, tz = string[:-6], string[-5:] tz = int(tz) offset = - 3600 * (tz / 100) - 60 * (tz % 100) else: date, offset = string, 0 - when = int(time.mktime(time.strptime(date, format))) + offset - return when, offset + localunixtime = int(calendar.timegm(time.strptime(date, format))) + unixtime = localunixtime + offset + return unixtime, offset def parsedate(string, formats=None): """parse a localized time string and return a (unixtime, offset) tuple. diff --git a/tests/test-parse-date b/tests/test-parse-date --- a/tests/test-parse-date +++ b/tests/test-parse-date @@ -1,5 +1,6 @@ #!/bin/sh +# This runs with TZ="GMT" hg init echo "test-parse-date" > a hg add a @@ -13,4 +14,21 @@ echo "fail" >> a hg ci -d "should fail" -m "fail" hg ci -d "100000000000000000 1400" -m "fail" hg ci -d "100000 1400000" -m "fail" + +# Check with local timezone other than GMT and with DST +TZ="PST+8PDT" +export TZ +# PST=UTC-8 / PDT=UTC-7 +hg debugrebuildstate +echo "a" > a +hg ci -d "2006-07-15 13:30" -m "summer@UTC" +hg debugrebuildstate +echo "b" > a +hg ci -d "2006-07-15 13:30 +0500" -m "summer@UTC+5" +hg debugrebuildstate +echo "c" > a +hg ci -d "2006-01-15 13:30" -m "winter@UTC" +hg debugrebuildstate +echo "d" > a +hg ci -d "2006-01-15 13:30 +0500" -m "winter@UTC+5" hg log --template '{date|date}\n' diff --git a/tests/test-parse-date.out b/tests/test-parse-date.out --- a/tests/test-parse-date.out +++ b/tests/test-parse-date.out @@ -12,6 +12,10 @@ rollback completed abort: impossible time zone offset: 1400000 transaction abort! rollback completed +Sun Jan 15 13:30:00 2006 +0500 +Sun Jan 15 13:30:00 2006 +0000 +Sat Jul 15 13:30:00 2006 +0500 +Sat Jul 15 13:30:00 2006 +0000 Sun Jun 11 00:26:40 2006 -0400 Sat Apr 15 13:30:00 2006 +0200 Sat Apr 15 13:30:00 2006 +0000