##// END OF EJS Templates
util: extract function that parses timezone string...
Yuya Nishihara -
r26126:7b625bae default
parent child Browse files
Show More
@@ -1371,11 +1371,8 def shortdate(date=None):
1371 """turn (timestamp, tzoff) tuple into iso 8631 date."""
1371 """turn (timestamp, tzoff) tuple into iso 8631 date."""
1372 return datestr(date, format='%Y-%m-%d')
1372 return datestr(date, format='%Y-%m-%d')
1373
1373
1374 def strdate(string, format, defaults=[]):
1374 def parsetimezone(tz):
1375 """parse a localized time string and return a (unixtime, offset) tuple.
1375 """parse a timezone string and return an offset integer"""
1376 if the string cannot be parsed, ValueError is raised."""
1377 def timezone(string):
1378 tz = string.split()[-1]
1379 if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit():
1376 if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit():
1380 sign = (tz[0] == "+") and 1 or -1
1377 sign = (tz[0] == "+") and 1 or -1
1381 hours = int(tz[1:3])
1378 hours = int(tz[1:3])
@@ -1385,8 +1382,11 def strdate(string, format, defaults=[])
1385 return 0
1382 return 0
1386 return None
1383 return None
1387
1384
1385 def strdate(string, format, defaults=[]):
1386 """parse a localized time string and return a (unixtime, offset) tuple.
1387 if the string cannot be parsed, ValueError is raised."""
1388 # NOTE: unixtime = localunixtime + offset
1388 # NOTE: unixtime = localunixtime + offset
1389 offset, date = timezone(string), string
1389 offset, date = parsetimezone(string.split()[-1]), string
1390 if offset is not None:
1390 if offset is not None:
1391 date = " ".join(string.split()[:-1])
1391 date = " ".join(string.split()[:-1])
1392
1392
General Comments 0
You need to be logged in to leave comments. Login now