comparison mercurial/util.py @ 29637:46b2ccce7fde stable

date: parse ISO-style Z and +hh:mm timezone specs
author Matt Mackall <mpm@selenic.com>
date Wed, 27 Jul 2016 15:20:34 -0500
parents 84ef4517de03
children 491ee264b9f6
comparison
equal deleted inserted replaced
29636:84ef4517de03 29637:46b2ccce7fde
1758 sign = (s[-5] == "+") and 1 or -1 1758 sign = (s[-5] == "+") and 1 or -1
1759 hours = int(s[-4:-2]) 1759 hours = int(s[-4:-2])
1760 minutes = int(s[-2:]) 1760 minutes = int(s[-2:])
1761 return -sign * (hours * 60 + minutes) * 60, s[:-5].rstrip() 1761 return -sign * (hours * 60 + minutes) * 60, s[:-5].rstrip()
1762 1762
1763 # ISO8601 trailing Z
1764 if s.endswith("Z") and s[-2:-1].isdigit():
1765 return 0, s[:-1]
1766
1767 # ISO8601-style [+-]hh:mm
1768 if (len(s) >= 6 and s[-6] in "+-" and s[-3] == ":" and
1769 s[-5:-3].isdigit() and s[-2:].isdigit()):
1770 sign = (s[-6] == "+") and 1 or -1
1771 hours = int(s[-5:-3])
1772 minutes = int(s[-2:])
1773 return -sign * (hours * 60 + minutes) * 60, s[:-6]
1774
1763 return None, s 1775 return None, s
1764 1776
1765 def strdate(string, format, defaults=[]): 1777 def strdate(string, format, defaults=[]):
1766 """parse a localized time string and return a (unixtime, offset) tuple. 1778 """parse a localized time string and return a (unixtime, offset) tuple.
1767 if the string cannot be parsed, ValueError is raised.""" 1779 if the string cannot be parsed, ValueError is raised."""