##// END OF EJS Templates
date: reallow negative timestamp, fix for Windows buggy gmtime() (issue2513)...
Florent Gallaire -
r28825:87c6ad22 default
parent child Browse files
Show More
@@ -1585,9 +1585,6 b" def datestr(date=None, format='%a %b %d "
1585 number of seconds away from UTC. if timezone is false, do not
1585 number of seconds away from UTC. if timezone is false, do not
1586 append time zone to string."""
1586 append time zone to string."""
1587 t, tz = date or makedate()
1587 t, tz = date or makedate()
1588 if t < 0:
1589 t = 0 # time.gmtime(lt) fails on Windows for lt < -43200
1590 tz = 0
1591 if "%1" in format or "%2" in format or "%z" in format:
1588 if "%1" in format or "%2" in format or "%z" in format:
1592 sign = (tz > 0) and "-" or "+"
1589 sign = (tz > 0) and "-" or "+"
1593 minutes = abs(tz) // 60
1590 minutes = abs(tz) // 60
@@ -1595,12 +1592,16 b" def datestr(date=None, format='%a %b %d "
1595 format = format.replace("%z", "%1%2")
1592 format = format.replace("%z", "%1%2")
1596 format = format.replace("%1", "%c%02d" % (sign, q))
1593 format = format.replace("%1", "%c%02d" % (sign, q))
1597 format = format.replace("%2", "%02d" % r)
1594 format = format.replace("%2", "%02d" % r)
1598 try:
1595 d = t - tz
1599 t = time.gmtime(float(t) - tz)
1596 if d > 0x7fffffff:
1600 except ValueError:
1597 d = 0x7fffffff
1601 # time was out of range
1598 elif d < -0x7fffffff:
1602 t = time.gmtime(sys.maxint)
1599 d = -0x7fffffff
1603 s = time.strftime(format, t)
1600 # Never use time.gmtime() and datetime.datetime.fromtimestamp()
1601 # because they use the gmtime() system call which is buggy on Windows
1602 # for negative values.
1603 t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=d)
1604 s = t.strftime(format)
1604 return s
1605 return s
1605
1606
1606 def shortdate(date=None):
1607 def shortdate(date=None):
@@ -1721,8 +1722,6 b' def parsedate(date, formats=None, bias=N'
1721 # to UTC+14
1722 # to UTC+14
1722 if abs(when) > 0x7fffffff:
1723 if abs(when) > 0x7fffffff:
1723 raise Abort(_('date exceeds 32 bits: %d') % when)
1724 raise Abort(_('date exceeds 32 bits: %d') % when)
1724 if when < 0:
1725 raise Abort(_('negative date value: %d') % when)
1726 if offset < -50400 or offset > 43200:
1725 if offset < -50400 or offset > 43200:
1727 raise Abort(_('impossible time zone offset: %d') % offset)
1726 raise Abort(_('impossible time zone offset: %d') % offset)
1728 return when, offset
1727 return when, offset
@@ -27,8 +27,21 b' commit date test'
27 $ hg commit -d '111111111111 0' -m commit-7
27 $ hg commit -d '111111111111 0' -m commit-7
28 abort: date exceeds 32 bits: 111111111111
28 abort: date exceeds 32 bits: 111111111111
29 [255]
29 [255]
30 $ hg commit -d '-7654321 3600' -m commit-7
30 $ hg commit -d '-111111111111 0' -m commit-7
31 abort: negative date value: -7654321
31 abort: date exceeds 32 bits: -111111111111
32 [255]
33 $ echo foo >> foo
34 $ hg commit -d '1901-12-13 20:45:53 +0000' -m commit-7-2
35 $ echo foo >> foo
36 $ hg commit -d '-2147483647 0' -m commit-7-3
37 $ hg log -T '{rev} {date|isodatesec}\n' -l2
38 3 1901-12-13 20:45:53 +0000
39 2 1901-12-13 20:45:53 +0000
40 $ hg commit -d '1901-12-13 20:45:52 +0000' -m commit-7
41 abort: date exceeds 32 bits: -2147483648
42 [255]
43 $ hg commit -d '-2147483648 0' -m commit-7
44 abort: date exceeds 32 bits: -2147483648
32 [255]
45 [255]
33
46
34 commit added file that has been deleted
47 commit added file that has been deleted
@@ -54,7 +67,7 b' commit added file that has been deleted'
54 dir/file
67 dir/file
55 committing manifest
68 committing manifest
56 committing changelog
69 committing changelog
57 committed changeset 2:d2a76177cb42
70 committed changeset 4:76aab26859d7
58
71
59 $ echo > dir.file
72 $ echo > dir.file
60 $ hg add
73 $ hg add
@@ -78,7 +91,7 b' commit added file that has been deleted'
78 dir/file
91 dir/file
79 committing manifest
92 committing manifest
80 committing changelog
93 committing changelog
81 committed changeset 3:1cd62a2d8db5
94 committed changeset 5:9a50557f1baf
82 $ cd ..
95 $ cd ..
83
96
84 $ hg commit -m commit-14 does-not-exist
97 $ hg commit -m commit-14 does-not-exist
@@ -102,7 +115,7 b' commit added file that has been deleted'
102 dir/file
115 dir/file
103 committing manifest
116 committing manifest
104 committing changelog
117 committing changelog
105 committed changeset 4:49176991390e
118 committed changeset 6:4b4c75bf422d
106
119
107 An empty date was interpreted as epoch origin
120 An empty date was interpreted as epoch origin
108
121
General Comments 0
You need to be logged in to leave comments. Login now