# HG changeset patch # User Matt Mackall # Date 1165432411 21600 # Node ID d6529582942a8dd7a122255a943dcdba286be167 # Parent e43b48f0f71888de007884707b59b9f70d956431 improve date parsing for numerous new date formats Add lots of new date formats Formats without year, month, or day default to current Strip leading and trailing whitespace diff -r e43b48f0f718 -r d6529582942a mercurial/util.py --- a/mercurial/util.py Wed Dec 06 13:13:27 2006 -0600 +++ b/mercurial/util.py Wed Dec 06 13:13:31 2006 -0600 @@ -72,8 +72,29 @@ raise Abort("decoding near '%s': %s!\n" % (sub, inst)) # used by parsedate -defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', - '%a %b %d %H:%M:%S %Y') +defaultdateformats = ( + '%Y-%m-%d %H:%M:%S', + '%Y-%m-%d %I:%M:%S%p', + '%Y-%m-%d %H:%M', + '%Y-%m-%d %I:%M%p', + '%Y-%m-%d', + '%m-%d', + '%m/%d', + '%m/%d/%y', + '%m/%d/%Y', + '%a %b %d %H:%M:%S %Y', + '%a %b %d %I:%M:%S%p %Y', + '%b %d %H:%M:%S %Y', + '%b %d %I:%M:%S%p', + '%b %d %H:%M', + '%b %d %I:%M%p', + '%b %d %Y', + '%b %d', + '%H:%M:%S', + '%I:%M:%SP', + '%H:%M', + '%I:%M%p', +) class SignalInterrupt(Exception): """Exception raised on SIGTERM and SIGHUP.""" @@ -1052,6 +1073,18 @@ offset = - 3600 * (tz / 100) - 60 * (tz % 100) else: date, offset = string, None + + # add missing elements + if '%y' not in format.lower(): + date += "@" + datestr(makedate(), "%Y", False) + format += "@%Y" + if '%m' not in format and '%b' not in format: + date += "@" + datestr(makedate(), "%m", False) + format += "@%m" + if '%d' not in format: + date += "@" + datestr(makedate(), "%d", False) + format += "@%d" + timetuple = time.strptime(date, format) localunixtime = int(calendar.timegm(timetuple)) if offset is None: @@ -1070,6 +1103,7 @@ return 0, 0 if not formats: formats = defaultdateformats + string = string.strip() try: when, offset = map(int, string.split(' ')) except ValueError: