Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 3809:4d93b37b5963
parsedate: add UTC and GMT timezones
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 06 Dec 2006 13:13:42 -0600 |
parents | d6529582942a |
children | bf6ab30559e6 |
comparison
equal
deleted
inserted
replaced
3808:d6529582942a | 3809:4d93b37b5963 |
---|---|
1059 return s | 1059 return s |
1060 | 1060 |
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(): |
1079 date += "@" + datestr(makedate(), "%Y", False) | 1081 date += "@" + datestr(makedate(), "%Y", False) |
1080 format += "@%Y" | 1082 format += "@%Y" |