Show More
@@ -1924,6 +1924,9 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 | ||
|
1927 | 1930 | >>> parsedate(' today ') == parsedate(\ |
|
1928 | 1931 | datetime.date.today().strftime('%b %d')) |
|
1929 | 1932 | True |
@@ -1938,6 +1941,20 b' def parsedate(date, formats=None, bias=N' | |||
|
1938 | 1941 | >>> tz == strtz |
|
1939 | 1942 | True |
|
1940 | 1943 | """ |
|
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 | """ | |
|
1941 | 1958 | if bias is None: |
|
1942 | 1959 | bias = {} |
|
1943 | 1960 | if not date: |
@@ -1984,15 +2001,15 b' def parsedate(date, formats=None, bias=N' | |||
|
1984 | 2001 | else: |
|
1985 | 2002 | break |
|
1986 | 2003 | else: |
|
1987 |
raise |
|
|
2004 | raise ValueError(_('invalid date: %r') % date) | |
|
1988 | 2005 | # validate explicit (probably user-specified) date and |
|
1989 | 2006 | # time zone offset. values must fit in signed 32 bits for |
|
1990 | 2007 | # current 32-bit linux runtimes. timezones go from UTC-12 |
|
1991 | 2008 | # to UTC+14 |
|
1992 | 2009 | if when < -0x80000000 or when > 0x7fffffff: |
|
1993 |
raise |
|
|
2010 | raise ValueError(_('date exceeds 32 bits: %d') % when) | |
|
1994 | 2011 | if offset < -50400 or offset > 43200: |
|
1995 |
raise |
|
|
2012 | raise ValueError(_('impossible time zone offset: %d') % offset) | |
|
1996 | 2013 | return when, offset |
|
1997 | 2014 | |
|
1998 | 2015 | def matchdate(date): |
General Comments 0
You need to be logged in to leave comments.
Login now