##// 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 522 return default
523 523 try:
524 524 return convert(v)
525 except ValueError:
525 except (ValueError, error.ParseError):
526 526 if desc is None:
527 527 desc = convert.__name__
528 528 raise error.ConfigError(_("%s.%s is not a valid %s ('%s')")
@@ -607,7 +607,7 b' class ui(object):'
607 607 (0, 0)
608 608 """
609 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 611 'date', untrusted)
612 612 return default
613 613
@@ -1924,9 +1924,6 b' def parsedate(date, formats=None, bias=N'
1924 1924 The date may be a "unixtime offset" string or in one of the specified
1925 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 1927 >>> parsedate(' today ') == parsedate(\
1931 1928 datetime.date.today().strftime('%b %d'))
1932 1929 True
@@ -1941,20 +1938,6 b' def parsedate(date, formats=None, bias=N'
1941 1938 >>> tz == strtz
1942 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 1941 if bias is None:
1959 1942 bias = {}
1960 1943 if not date:
@@ -2001,15 +1984,15 b' def rawparsedate(date, formats=None, bia'
2001 1984 else:
2002 1985 break
2003 1986 else:
2004 raise ValueError(_('invalid date: %r') % date)
1987 raise error.ParseError(_('invalid date: %r') % date)
2005 1988 # validate explicit (probably user-specified) date and
2006 1989 # time zone offset. values must fit in signed 32 bits for
2007 1990 # current 32-bit linux runtimes. timezones go from UTC-12
2008 1991 # to UTC+14
2009 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 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 1996 return when, offset
2014 1997
2015 1998 def matchdate(date):
@@ -15,20 +15,20 b' commit date test'
15 15 $ hg commit -d '0 0' -m commit-1
16 16 $ echo foo >> foo
17 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 19 [255]
20 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 22 [255]
23 23 $ hg commit -d 'foo bar' -m commit-5
24 abort: invalid date: 'foo bar'
24 hg: parse error: invalid date: 'foo bar'
25 25 [255]
26 26 $ hg commit -d ' 1 4444' -m commit-6
27 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 29 [255]
30 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 32 [255]
33 33 $ echo foo >> foo
34 34 $ hg commit -d '1901-12-13 20:45:52 +0000' -m commit-7-2
@@ -38,10 +38,10 b' commit date test'
38 38 3 1901-12-13 20:45:52 +0000
39 39 2 1901-12-13 20:45:52 +0000
40 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 42 [255]
43 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 45 [255]
46 46
47 47 commit added file that has been deleted
@@ -1513,7 +1513,7 b' glog always reorders nodes which explain'
1513 1513 ('symbol', 'date')
1514 1514 ('string', '2 0 to 4 0')))
1515 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 1517 [255]
1518 1518 $ testlog --prune 31 --prune 32
1519 1519 []
@@ -17,13 +17,13 b' This runs with TZ="GMT"'
17 17 $ hg ci -d "1150000000 14400" -m "rev 4 (merge)"
18 18 $ echo "fail" >> a
19 19 $ hg ci -d "should fail" -m "fail"
20 abort: invalid date: 'should fail'
20 hg: parse error: invalid date: 'should fail'
21 21 [255]
22 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 24 [255]
25 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 27 [255]
28 28
29 29 Check with local timezone other than GMT and with DST
@@ -413,7 +413,7 b' quoting needed'
413 413 hg: parse error: invalid \x escape
414 414 [255]
415 415 $ log 'date(tip)'
416 abort: invalid date: 'tip'
416 hg: parse error: invalid date: 'tip'
417 417 [255]
418 418 $ log '0:date'
419 419 abort: unknown revision 'date'!
General Comments 0
You need to be logged in to leave comments. Login now