##// END OF EJS Templates
util.strdate: compute timestamp using UTC, not local timezone
Jose M. Prieto -
r3255:e96d2956 default
parent child Browse files
Show More
@@ -15,7 +15,7 b' platform-specific details from the core.'
15 15 from i18n import gettext as _
16 16 from demandload import *
17 17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
18 demandload(globals(), "os threading time")
18 demandload(globals(), "os threading time calendar")
19 19
20 20 # used by parsedate
21 21 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M',
@@ -903,14 +903,16 b" def strdate(string, format='%a %b %d %H:"
903 903 (string[-5] == '+' or string[-5] == '-') and
904 904 string[-6].isspace())
905 905
906 # NOTE: unixtime = localunixtime + offset
906 907 if hastimezone(string):
907 908 date, tz = string[:-6], string[-5:]
908 909 tz = int(tz)
909 910 offset = - 3600 * (tz / 100) - 60 * (tz % 100)
910 911 else:
911 912 date, offset = string, 0
912 when = int(time.mktime(time.strptime(date, format))) + offset
913 return when, offset
913 localunixtime = int(calendar.timegm(time.strptime(date, format)))
914 unixtime = localunixtime + offset
915 return unixtime, offset
914 916
915 917 def parsedate(string, formats=None):
916 918 """parse a localized time string and return a (unixtime, offset) tuple.
@@ -1,5 +1,6 b''
1 1 #!/bin/sh
2 2
3 # This runs with TZ="GMT"
3 4 hg init
4 5 echo "test-parse-date" > a
5 6 hg add a
@@ -13,4 +14,21 b' echo "fail" >> a'
13 14 hg ci -d "should fail" -m "fail"
14 15 hg ci -d "100000000000000000 1400" -m "fail"
15 16 hg ci -d "100000 1400000" -m "fail"
17
18 # Check with local timezone other than GMT and with DST
19 TZ="PST+8PDT"
20 export TZ
21 # PST=UTC-8 / PDT=UTC-7
22 hg debugrebuildstate
23 echo "a" > a
24 hg ci -d "2006-07-15 13:30" -m "summer@UTC"
25 hg debugrebuildstate
26 echo "b" > a
27 hg ci -d "2006-07-15 13:30 +0500" -m "summer@UTC+5"
28 hg debugrebuildstate
29 echo "c" > a
30 hg ci -d "2006-01-15 13:30" -m "winter@UTC"
31 hg debugrebuildstate
32 echo "d" > a
33 hg ci -d "2006-01-15 13:30 +0500" -m "winter@UTC+5"
16 34 hg log --template '{date|date}\n'
@@ -12,6 +12,10 b' rollback completed'
12 12 abort: impossible time zone offset: 1400000
13 13 transaction abort!
14 14 rollback completed
15 Sun Jan 15 13:30:00 2006 +0500
16 Sun Jan 15 13:30:00 2006 +0000
17 Sat Jul 15 13:30:00 2006 +0500
18 Sat Jul 15 13:30:00 2006 +0000
15 19 Sun Jun 11 00:26:40 2006 -0400
16 20 Sat Apr 15 13:30:00 2006 +0200
17 21 Sat Apr 15 13:30:00 2006 +0000
General Comments 0
You need to be logged in to leave comments. Login now