##// END OF EJS Templates
parsedate: add UTC and GMT timezones
Matt Mackall -
r3809:4d93b37b default
parent child Browse files
Show More
@@ -1061,18 +1061,20 b" def datestr(date=None, format='%a %b %d "
1061 def strdate(string, format='%a %b %d %H:%M:%S %Y'):
1061 def strdate(string, format='%a %b %d %H:%M:%S %Y'):
1062 """parse a localized time string and return a (unixtime, offset) tuple.
1062 """parse a localized time string and return a (unixtime, offset) tuple.
1063 if the string cannot be parsed, ValueError is raised."""
1063 if the string cannot be parsed, ValueError is raised."""
1064 def hastimezone(string):
1064 def timezone(string):
1065 return (string[-4:].isdigit() and
1065 tz = string.split()[-1]
1066 (string[-5] == '+' or string[-5] == '-') and
1066 if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit():
1067 string[-6].isspace())
1067 tz = int(tz)
1068 offset = - 3600 * (tz / 100) - 60 * (tz % 100)
1069 return offset
1070 if tz == "GMT" or tz == "UTC":
1071 return 0
1072 return None
1068
1073
1069 # NOTE: unixtime = localunixtime + offset
1074 # NOTE: unixtime = localunixtime + offset
1070 if hastimezone(string):
1075 offset, date = timezone(string), string
1071 date, tz = string[:-6], string[-5:]
1076 if offset != None:
1072 tz = int(tz)
1077 date = " ".join(string.split()[:-1])
1073 offset = - 3600 * (tz / 100) - 60 * (tz % 100)
1074 else:
1075 date, offset = string, None
1076
1078
1077 # add missing elements
1079 # add missing elements
1078 if '%y' not in format.lower():
1080 if '%y' not in format.lower():
General Comments 0
You need to be logged in to leave comments. Login now