Parse an IMAP4 INTERNALDATE string. Return corresponding local time. The return value is a time.struct_time tuple or None if the string has wrong format.
(resp)
| 1443 | Mon2num = {s.encode():n+1 for n, s in enumerate(Months[1:])} |
| 1444 | |
| 1445 | def Internaldate2tuple(resp): |
| 1446 | """Parse an IMAP4 INTERNALDATE string. |
| 1447 | |
| 1448 | Return corresponding local time. The return value is a |
| 1449 | time.struct_time tuple or None if the string has wrong format. |
| 1450 | """ |
| 1451 | |
| 1452 | mo = InternalDate.match(resp) |
| 1453 | if not mo: |
| 1454 | return None |
| 1455 | |
| 1456 | mon = Mon2num[mo.group('mon')] |
| 1457 | zonen = mo.group('zonen') |
| 1458 | |
| 1459 | day = int(mo.group('day')) |
| 1460 | year = int(mo.group('year')) |
| 1461 | hour = int(mo.group('hour')) |
| 1462 | min = int(mo.group('min')) |
| 1463 | sec = int(mo.group('sec')) |
| 1464 | zoneh = int(mo.group('zoneh')) |
| 1465 | zonem = int(mo.group('zonem')) |
| 1466 | |
| 1467 | # INTERNALDATE timezone must be subtracted to get UT |
| 1468 | |
| 1469 | zone = (zoneh*60 + zonem)*60 |
| 1470 | if zonen == b'-': |
| 1471 | zone = -zone |
| 1472 | |
| 1473 | tt = (year, mon, day, hour, min, sec, -1, -1, -1) |
| 1474 | utc = calendar.timegm(tt) - zone |
| 1475 | |
| 1476 | return time.localtime(utc) |
| 1477 | |
| 1478 | |
| 1479 |