##// END OF EJS Templates
improve date parsing for numerous new date formats...
Matt Mackall -
r3808:d6529582 default
parent child Browse files
Show More
@@ -72,8 +72,29 b' def localsub(s, a, b=None):'
72 72 raise Abort("decoding near '%s': %s!\n" % (sub, inst))
73 73
74 74 # used by parsedate
75 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M',
76 '%a %b %d %H:%M:%S %Y')
75 defaultdateformats = (
76 '%Y-%m-%d %H:%M:%S',
77 '%Y-%m-%d %I:%M:%S%p',
78 '%Y-%m-%d %H:%M',
79 '%Y-%m-%d %I:%M%p',
80 '%Y-%m-%d',
81 '%m-%d',
82 '%m/%d',
83 '%m/%d/%y',
84 '%m/%d/%Y',
85 '%a %b %d %H:%M:%S %Y',
86 '%a %b %d %I:%M:%S%p %Y',
87 '%b %d %H:%M:%S %Y',
88 '%b %d %I:%M:%S%p',
89 '%b %d %H:%M',
90 '%b %d %I:%M%p',
91 '%b %d %Y',
92 '%b %d',
93 '%H:%M:%S',
94 '%I:%M:%SP',
95 '%H:%M',
96 '%I:%M%p',
97 )
77 98
78 99 class SignalInterrupt(Exception):
79 100 """Exception raised on SIGTERM and SIGHUP."""
@@ -1052,6 +1073,18 b" def strdate(string, format='%a %b %d %H:"
1052 1073 offset = - 3600 * (tz / 100) - 60 * (tz % 100)
1053 1074 else:
1054 1075 date, offset = string, None
1076
1077 # add missing elements
1078 if '%y' not in format.lower():
1079 date += "@" + datestr(makedate(), "%Y", False)
1080 format += "@%Y"
1081 if '%m' not in format and '%b' not in format:
1082 date += "@" + datestr(makedate(), "%m", False)
1083 format += "@%m"
1084 if '%d' not in format:
1085 date += "@" + datestr(makedate(), "%d", False)
1086 format += "@%d"
1087
1055 1088 timetuple = time.strptime(date, format)
1056 1089 localunixtime = int(calendar.timegm(timetuple))
1057 1090 if offset is None:
@@ -1070,6 +1103,7 b' def parsedate(string, formats=None):'
1070 1103 return 0, 0
1071 1104 if not formats:
1072 1105 formats = defaultdateformats
1106 string = string.strip()
1073 1107 try:
1074 1108 when, offset = map(int, string.split(' '))
1075 1109 except ValueError:
General Comments 0
You need to be logged in to leave comments. Login now