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)
| 1761 | Mon2num = {s.encode():n+1 for n, s in enumerate(Months[1:])} |
| 1762 | |
| 1763 | def Internaldate2tuple(resp): |
| 1764 | """Parse an IMAP4 INTERNALDATE string. |
| 1765 | |
| 1766 | Return corresponding local time. The return value is a |
| 1767 | time.struct_time tuple or None if the string has wrong format. |
| 1768 | """ |
| 1769 | |
| 1770 | mo = InternalDate.match(resp) |
| 1771 | if not mo: |
| 1772 | return None |
| 1773 | |
| 1774 | mon = Mon2num[mo.group('mon')] |
| 1775 | zonen = mo.group('zonen') |
| 1776 | |
| 1777 | day = int(mo.group('day')) |
| 1778 | year = int(mo.group('year')) |
| 1779 | hour = int(mo.group('hour')) |
| 1780 | min = int(mo.group('min')) |
| 1781 | sec = int(mo.group('sec')) |
| 1782 | zoneh = int(mo.group('zoneh')) |
| 1783 | zonem = int(mo.group('zonem')) |
| 1784 | |
| 1785 | # INTERNALDATE timezone must be subtracted to get UT |
| 1786 | |
| 1787 | zone = (zoneh*60 + zonem)*60 |
| 1788 | if zonen == b'-': |
| 1789 | zone = -zone |
| 1790 | |
| 1791 | tt = (year, mon, day, hour, min, sec, -1, -1, -1) |
| 1792 | utc = calendar.timegm(tt) - zone |
| 1793 | |
| 1794 | return time.localtime(utc) |
| 1795 | |
| 1796 | |
| 1797 |