diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -913,7 +913,7 @@ tzoffset = None tz = evalfuncarg(context, mapping, args[1]) if isinstance(tz, str): - tzoffset, remainder = util.parsetimezone(tz) + tzoffset, remainder = dateutil.parsetimezone(tz) if remainder: tzoffset = None if tzoffset is None: diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1906,34 +1906,6 @@ limit -= len(s) yield s -def parsetimezone(s): - """find a trailing timezone, if any, in string, and return a - (offset, remainder) pair""" - - if s.endswith("GMT") or s.endswith("UTC"): - return 0, s[:-3].rstrip() - - # Unix-style timezones [+-]hhmm - if len(s) >= 5 and s[-5] in "+-" and s[-4:].isdigit(): - sign = (s[-5] == "+") and 1 or -1 - hours = int(s[-4:-2]) - minutes = int(s[-2:]) - return -sign * (hours * 60 + minutes) * 60, s[:-5].rstrip() - - # ISO8601 trailing Z - if s.endswith("Z") and s[-2:-1].isdigit(): - return 0, s[:-1] - - # ISO8601-style [+-]hh:mm - if (len(s) >= 6 and s[-6] in "+-" and s[-3] == ":" and - s[-5:-3].isdigit() and s[-2:].isdigit()): - sign = (s[-6] == "+") and 1 or -1 - hours = int(s[-5:-3]) - minutes = int(s[-2:]) - return -sign * (hours * 60 + minutes) * 60, s[:-6] - - return None, s - def strdate(string, format, defaults=None): """parse a localized time string and return a (unixtime, offset) tuple. if the string cannot be parsed, ValueError is raised.""" @@ -1941,7 +1913,7 @@ defaults = {} # NOTE: unixtime = localunixtime + offset - offset, date = parsetimezone(string) + offset, date = dateutil.parsetimezone(string) # add missing elements from defaults usenow = False # default to using biased defaults @@ -3877,3 +3849,9 @@ nouideprecwarn(msg, "4.6") return dateutil.shortdate(*args, **kwargs) +def parsetimezone(*args, **kwargs): + msg = ("'util.parsetimezone' is deprecated, " + "use 'utils.dateutil.parsetimezone'") + nouideprecwarn(msg, "4.6") + return dateutil.parsetimezone(*args, **kwargs) + diff --git a/mercurial/utils/dateutil.py b/mercurial/utils/dateutil.py --- a/mercurial/utils/dateutil.py +++ b/mercurial/utils/dateutil.py @@ -111,3 +111,31 @@ """turn (timestamp, tzoff) tuple into iso 8631 date.""" return datestr(date, format='%Y-%m-%d') +def parsetimezone(s): + """find a trailing timezone, if any, in string, and return a + (offset, remainder) pair""" + + if s.endswith("GMT") or s.endswith("UTC"): + return 0, s[:-3].rstrip() + + # Unix-style timezones [+-]hhmm + if len(s) >= 5 and s[-5] in "+-" and s[-4:].isdigit(): + sign = (s[-5] == "+") and 1 or -1 + hours = int(s[-4:-2]) + minutes = int(s[-2:]) + return -sign * (hours * 60 + minutes) * 60, s[:-5].rstrip() + + # ISO8601 trailing Z + if s.endswith("Z") and s[-2:-1].isdigit(): + return 0, s[:-1] + + # ISO8601-style [+-]hh:mm + if (len(s) >= 6 and s[-6] in "+-" and s[-3] == ":" and + s[-5:-3].isdigit() and s[-2:].isdigit()): + sign = (s[-6] == "+") and 1 or -1 + hours = int(s[-5:-3]) + minutes = int(s[-2:]) + return -sign * (hours * 60 + minutes) * 60, s[:-6] + + return None, s +