Show More
@@ -1371,22 +1371,22 b' def shortdate(date=None):' | |||
|
1371 | 1371 | """turn (timestamp, tzoff) tuple into iso 8631 date.""" |
|
1372 | 1372 | return datestr(date, format='%Y-%m-%d') |
|
1373 | 1373 | |
|
1374 | def parsetimezone(tz): | |
|
1375 | """parse a timezone string and return an offset integer""" | |
|
1376 | if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit(): | |
|
1377 | sign = (tz[0] == "+") and 1 or -1 | |
|
1378 | hours = int(tz[1:3]) | |
|
1379 | minutes = int(tz[3:5]) | |
|
1380 | return -sign * (hours * 60 + minutes) * 60 | |
|
1381 | if tz == "GMT" or tz == "UTC": | |
|
1382 | return 0 | |
|
1383 | return None | |
|
1384 | ||
|
1374 | 1385 | def strdate(string, format, defaults=[]): |
|
1375 | 1386 | """parse a localized time string and return a (unixtime, offset) tuple. |
|
1376 | 1387 | 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(): | |
|
1380 | sign = (tz[0] == "+") and 1 or -1 | |
|
1381 | hours = int(tz[1:3]) | |
|
1382 | minutes = int(tz[3:5]) | |
|
1383 | return -sign * (hours * 60 + minutes) * 60 | |
|
1384 | if tz == "GMT" or tz == "UTC": | |
|
1385 | return 0 | |
|
1386 | return None | |
|
1387 | ||
|
1388 | 1388 | # NOTE: unixtime = localunixtime + offset |
|
1389 | offset, date = timezone(string), string | |
|
1389 | offset, date = parsetimezone(string.split()[-1]), string | |
|
1390 | 1390 | if offset is not None: |
|
1391 | 1391 | date = " ".join(string.split()[:-1]) |
|
1392 | 1392 |
General Comments 0
You need to be logged in to leave comments.
Login now