Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 6139:989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
commit (aborts _after_ typing in a commit message)
backout (aborted after the initial revert)
tag (edited .hgtags and couldn't commit)
import (patch applied, then commit fails)
qnew (aborts on bad dates, but writes any valid date into the # Date header)
qrefresh (like qnew)
sign (like tag)
fetch (merge, merge, merge, merge, abort)
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sun, 17 Feb 2008 21:34:28 +0100 |
parents | be91a77b7f18 |
children | 47e6d5d5913a |
line wrap: on
line diff
--- a/mercurial/util.py Sun Feb 17 12:53:57 2008 +0100 +++ b/mercurial/util.py Sun Feb 17 21:34:28 2008 +0100 @@ -1572,17 +1572,21 @@ unixtime = localunixtime + offset return unixtime, offset -def parsedate(string, formats=None, defaults=None): - """parse a localized time string and return a (unixtime, offset) tuple. +def parsedate(date, formats=None, defaults=None): + """parse a localized date/time string and return a (unixtime, offset) tuple. + The date may be a "unixtime offset" string or in one of the specified - formats.""" - if not string: + formats. If the date already is a (unixtime, offset) tuple, it is returned. + """ + if not date: return 0, 0 + if type(date) is type((0, 0)) and len(date) == 2: + return date if not formats: formats = defaultdateformats - string = string.strip() + date = date.strip() try: - when, offset = map(int, string.split(' ')) + when, offset = map(int, date.split(' ')) except ValueError: # fill out defaults if not defaults: @@ -1599,13 +1603,13 @@ for format in formats: try: - when, offset = strdate(string, format, defaults) + when, offset = strdate(date, format, defaults) except (ValueError, OverflowError): pass else: break else: - raise Abort(_('invalid date: %r ') % string) + raise Abort(_('invalid date: %r ') % date) # validate explicit (probably user-specified) date and # time zone offset. values must fit in signed 32 bits for # current 32-bit linux runtimes. timezones go from UTC-12