##// END OF EJS Templates
util: raise ParseError when parsing dates (BC)...
Boris Feld -
r32462:bb18728e default
parent child Browse files
Show More
@@ -522,7 +522,7 b' class ui(object):'
522 return default
522 return default
523 try:
523 try:
524 return convert(v)
524 return convert(v)
525 except ValueError:
525 except (ValueError, error.ParseError):
526 if desc is None:
526 if desc is None:
527 desc = convert.__name__
527 desc = convert.__name__
528 raise error.ConfigError(_("%s.%s is not a valid %s ('%s')")
528 raise error.ConfigError(_("%s.%s is not a valid %s ('%s')")
@@ -607,7 +607,7 b' class ui(object):'
607 (0, 0)
607 (0, 0)
608 """
608 """
609 if self.config(section, name, default, untrusted):
609 if self.config(section, name, default, untrusted):
610 return self.configwith(util.rawparsedate, section, name, default,
610 return self.configwith(util.parsedate, section, name, default,
611 'date', untrusted)
611 'date', untrusted)
612 return default
612 return default
613
613
@@ -1924,9 +1924,6 b' def parsedate(date, formats=None, bias=N'
1924 The date may be a "unixtime offset" string or in one of the specified
1924 The date may be a "unixtime offset" string or in one of the specified
1925 formats. If the date already is a (unixtime, offset) tuple, it is returned.
1925 formats. If the date already is a (unixtime, offset) tuple, it is returned.
1926
1926
1927 This function calls rawparsedate and convert ValueError to Abort for
1928 functions that needs higher level exception.
1929
1930 >>> parsedate(' today ') == parsedate(\
1927 >>> parsedate(' today ') == parsedate(\
1931 datetime.date.today().strftime('%b %d'))
1928 datetime.date.today().strftime('%b %d'))
1932 True
1929 True
@@ -1941,20 +1938,6 b' def parsedate(date, formats=None, bias=N'
1941 >>> tz == strtz
1938 >>> tz == strtz
1942 True
1939 True
1943 """
1940 """
1944 try:
1945 return rawparsedate(date, formats=formats, bias=bias)
1946 except ValueError as exception:
1947 raise Abort(str(exception))
1948
1949 def rawparsedate(date, formats=None, bias=None):
1950 """parse a localized date/time and return a (unixtime, offset) tuple.
1951
1952 The date may be a "unixtime offset" string or in one of the specified
1953 formats. If the date already is a (unixtime, offset) tuple, it is returned.
1954
1955 See docstring of parsedate for example.
1956 Raise ValueError for invalid date value.
1957 """
1958 if bias is None:
1941 if bias is None:
1959 bias = {}
1942 bias = {}
1960 if not date:
1943 if not date:
@@ -2001,15 +1984,15 b' def rawparsedate(date, formats=None, bia'
2001 else:
1984 else:
2002 break
1985 break
2003 else:
1986 else:
2004 raise ValueError(_('invalid date: %r') % date)
1987 raise error.ParseError(_('invalid date: %r') % date)
2005 # validate explicit (probably user-specified) date and
1988 # validate explicit (probably user-specified) date and
2006 # time zone offset. values must fit in signed 32 bits for
1989 # time zone offset. values must fit in signed 32 bits for
2007 # current 32-bit linux runtimes. timezones go from UTC-12
1990 # current 32-bit linux runtimes. timezones go from UTC-12
2008 # to UTC+14
1991 # to UTC+14
2009 if when < -0x80000000 or when > 0x7fffffff:
1992 if when < -0x80000000 or when > 0x7fffffff:
2010 raise ValueError(_('date exceeds 32 bits: %d') % when)
1993 raise error.ParseError(_('date exceeds 32 bits: %d') % when)
2011 if offset < -50400 or offset > 43200:
1994 if offset < -50400 or offset > 43200:
2012 raise ValueError(_('impossible time zone offset: %d') % offset)
1995 raise error.ParseError(_('impossible time zone offset: %d') % offset)
2013 return when, offset
1996 return when, offset
2014
1997
2015 def matchdate(date):
1998 def matchdate(date):
@@ -15,20 +15,20 b' commit date test'
15 $ hg commit -d '0 0' -m commit-1
15 $ hg commit -d '0 0' -m commit-1
16 $ echo foo >> foo
16 $ echo foo >> foo
17 $ hg commit -d '1 4444444' -m commit-3
17 $ hg commit -d '1 4444444' -m commit-3
18 abort: impossible time zone offset: 4444444
18 hg: parse error: impossible time zone offset: 4444444
19 [255]
19 [255]
20 $ hg commit -d '1 15.1' -m commit-4
20 $ hg commit -d '1 15.1' -m commit-4
21 abort: invalid date: '1\t15.1'
21 hg: parse error: invalid date: '1\t15.1'
22 [255]
22 [255]
23 $ hg commit -d 'foo bar' -m commit-5
23 $ hg commit -d 'foo bar' -m commit-5
24 abort: invalid date: 'foo bar'
24 hg: parse error: invalid date: 'foo bar'
25 [255]
25 [255]
26 $ hg commit -d ' 1 4444' -m commit-6
26 $ hg commit -d ' 1 4444' -m commit-6
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 hg: parse error: date exceeds 32 bits: 111111111111
29 [255]
29 [255]
30 $ hg commit -d '-111111111111 0' -m commit-7
30 $ hg commit -d '-111111111111 0' -m commit-7
31 abort: date exceeds 32 bits: -111111111111
31 hg: parse error: date exceeds 32 bits: -111111111111
32 [255]
32 [255]
33 $ echo foo >> foo
33 $ echo foo >> foo
34 $ hg commit -d '1901-12-13 20:45:52 +0000' -m commit-7-2
34 $ hg commit -d '1901-12-13 20:45:52 +0000' -m commit-7-2
@@ -38,10 +38,10 b' commit date test'
38 3 1901-12-13 20:45:52 +0000
38 3 1901-12-13 20:45:52 +0000
39 2 1901-12-13 20:45:52 +0000
39 2 1901-12-13 20:45:52 +0000
40 $ hg commit -d '1901-12-13 20:45:51 +0000' -m commit-7
40 $ hg commit -d '1901-12-13 20:45:51 +0000' -m commit-7
41 abort: date exceeds 32 bits: -2147483649
41 hg: parse error: date exceeds 32 bits: -2147483649
42 [255]
42 [255]
43 $ hg commit -d '-2147483649 0' -m commit-7
43 $ hg commit -d '-2147483649 0' -m commit-7
44 abort: date exceeds 32 bits: -2147483649
44 hg: parse error: date exceeds 32 bits: -2147483649
45 [255]
45 [255]
46
46
47 commit added file that has been deleted
47 commit added file that has been deleted
@@ -1513,7 +1513,7 b' glog always reorders nodes which explain'
1513 ('symbol', 'date')
1513 ('symbol', 'date')
1514 ('string', '2 0 to 4 0')))
1514 ('string', '2 0 to 4 0')))
1515 $ hg log -G -d 'brace ) in a date'
1515 $ hg log -G -d 'brace ) in a date'
1516 abort: invalid date: 'brace ) in a date'
1516 hg: parse error: invalid date: 'brace ) in a date'
1517 [255]
1517 [255]
1518 $ testlog --prune 31 --prune 32
1518 $ testlog --prune 31 --prune 32
1519 []
1519 []
@@ -17,13 +17,13 b' This runs with TZ="GMT"'
17 $ hg ci -d "1150000000 14400" -m "rev 4 (merge)"
17 $ hg ci -d "1150000000 14400" -m "rev 4 (merge)"
18 $ echo "fail" >> a
18 $ echo "fail" >> a
19 $ hg ci -d "should fail" -m "fail"
19 $ hg ci -d "should fail" -m "fail"
20 abort: invalid date: 'should fail'
20 hg: parse error: invalid date: 'should fail'
21 [255]
21 [255]
22 $ hg ci -d "100000000000000000 1400" -m "fail"
22 $ hg ci -d "100000000000000000 1400" -m "fail"
23 abort: date exceeds 32 bits: 100000000000000000
23 hg: parse error: date exceeds 32 bits: 100000000000000000
24 [255]
24 [255]
25 $ hg ci -d "100000 1400000" -m "fail"
25 $ hg ci -d "100000 1400000" -m "fail"
26 abort: impossible time zone offset: 1400000
26 hg: parse error: impossible time zone offset: 1400000
27 [255]
27 [255]
28
28
29 Check with local timezone other than GMT and with DST
29 Check with local timezone other than GMT and with DST
@@ -413,7 +413,7 b' quoting needed'
413 hg: parse error: invalid \x escape
413 hg: parse error: invalid \x escape
414 [255]
414 [255]
415 $ log 'date(tip)'
415 $ log 'date(tip)'
416 abort: invalid date: 'tip'
416 hg: parse error: invalid date: 'tip'
417 [255]
417 [255]
418 $ log '0:date'
418 $ log '0:date'
419 abort: unknown revision 'date'!
419 abort: unknown revision 'date'!
General Comments 0
You need to be logged in to leave comments. Login now