merge with crew
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Thu, 05 Oct 2006 00:14:21 +0200
changeset 3253 03acd01520ac
parent 3252 c9cd63a6fce9 (diff)
parent 3249 168485fa44ba (current diff)
child 3258 53d6bcccdbef
child 3259 1f1af9b273e8
merge with crew
--- a/doc/hg.1.txt
+++ b/doc/hg.1.txt
@@ -127,6 +127,42 @@ SPECIFYING MULTIPLE REVISIONS
     A range acts as a closed interval.  This means that a range of 3:5
     gives 3, 4 and 5.  Similarly, a range of 4:2 gives 4, 3, and 2.
 
+DATE FORMATS
+------------
+
+    Some commands (backout, commit, tag) allow the user to specify a date.
+    Possible formats for dates are:
+
+YYYY-mm-dd \HH:MM[:SS] [(+|-)NNNN]::
+    This is a subset of ISO 8601, allowing just the recommended notations
+    for date and time. The last part represents the timezone; if omitted,
+    local time is assumed. Examples:
+
+    "2005-08-22 03:27 -0700"
+
+    "2006-04-19 21:39:51"
+
+aaa bbb dd HH:MM:SS YYYY [(+|-)NNNN]::
+    This is the date format used by the C library. Here, aaa stands for
+    abbreviated weekday name and bbb for abbreviated month name. The last
+    part represents the timezone; if omitted, local time is assumed.
+    Examples:
+
+    "Mon Aug 22 03:27:00 2005 -0700"
+
+    "Wed Apr 19 21:39:51 2006"
+
+unixtime offset::
+    This is the internal representation format for dates. unixtime is
+    the number of seconds since the epoch (1970-01-01 00:00 UTC). offset
+    is the offset of the local timezone, in seconds west of UTC (negative
+    if the timezone is east of UTC).
+    Examples:
+
+    "1124706420 25200" (2005-08-22 03:27:00 -0700)
+
+    "1145475591 -7200" (2006-04-19 21:39:51 +0200)
+
 ENVIRONMENT VARIABLES
 ---------------------
 
--- 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,22 @@ 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
+        date, offset = string, None
+    timetuple = time.strptime(date, format)
+    localunixtime = int(calendar.timegm(timetuple))
+    if offset is None:
+        # local timezone
+        unixtime = int(time.mktime(timetuple))
+        offset = unixtime - localunixtime
+    else:
+        unixtime = localunixtime + offset
+    return unixtime, offset
 
 def parsedate(string, formats=None):
     """parse a localized time string and return a (unixtime, offset) tuple.
@@ -929,7 +937,9 @@ def parsedate(string, formats=None):
             else:
                 break
         else:
-            raise ValueError(_('invalid date: %r') % string)
+            raise ValueError(_('invalid date: %r '
+                               'see hg(1) manual page for details')
+                             % string)
     # validate explicit (probably user-specified) date and
     # time zone offset. values must fit in signed 32 bits for
     # current 32-bit linux runtimes. timezones go from UTC-12
--- a/tests/test-commit.out
+++ b/tests/test-commit.out
@@ -1,13 +1,13 @@
 abort: impossible time zone offset: 4444444
 transaction abort!
 rollback completed
-abort: invalid date: '1\t15.1'
+abort: invalid date: '1\t15.1' see hg(1) manual page for details
 transaction abort!
 rollback completed
-abort: invalid date: 'foo bar'
+abort: invalid date: 'foo bar' see hg(1) manual page for details
 transaction abort!
 rollback completed
-abort: invalid date: ' 1 4444'
+abort: invalid date: ' 1 4444' see hg(1) manual page for details
 transaction abort!
 rollback completed
 abort: date exceeds 32 bits: 111111111111
--- 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-7"
+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-8"
+hg debugrebuildstate
+echo "d" > a
+hg ci -d "2006-01-15 13:30 +0500" -m "winter@UTC+5"
 hg log --template '{date|date}\n'
--- a/tests/test-parse-date.out
+++ b/tests/test-parse-date.out
@@ -3,7 +3,7 @@ changeset 3:107ce1ee2b43 backs out chang
 merging with changeset 2:e6c3abc120e7
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
-abort: invalid date: 'should fail'
+abort: invalid date: 'should fail' see hg(1) manual page for details
 transaction abort!
 rollback completed
 abort: date exceeds 32 bits: 100000000000000000
@@ -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 -0800
+Sat Jul 15 13:30:00 2006 +0500
+Sat Jul 15 13:30:00 2006 -0700
 Sun Jun 11 00:26:40 2006 -0400
 Sat Apr 15 13:30:00 2006 +0200
 Sat Apr 15 13:30:00 2006 +0000