MCPcopy Index your code
hub / github.com/python/cpython / Time2Internaldate

Function Time2Internaldate

Lib/imaplib.py:1821–1858  ·  view source on GitHub ↗

Convert date_time to IMAP4 INTERNALDATE representation. Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The date_time argument can be a number (int or float) representing seconds since epoch (as returned by time.time()), a 9-tuple representing local time, an instance of time

(date_time)

Source from the content-addressed store, hash-verified

1819
1820
1821def Time2Internaldate(date_time):
1822
1823 """Convert date_time to IMAP4 INTERNALDATE representation.
1824
1825 Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The
1826 date_time argument can be a number (int or float) representing
1827 seconds since epoch (as returned by time.time()), a 9-tuple
1828 representing local time, an instance of time.struct_time (as
1829 returned by time.localtime()), an aware datetime instance or a
1830 double-quoted string. In the last case, it is assumed to already
1831 be in the correct format.
1832 """
1833 if isinstance(date_time, (int, float)):
1834 dt = datetime.fromtimestamp(date_time,
1835 timezone.utc).astimezone()
1836 elif isinstance(date_time, tuple):
1837 try:
1838 gmtoff = date_time.tm_gmtoff
1839 except AttributeError:
1840 if time.daylight:
1841 dst = date_time[8]
1842 if dst == -1:
1843 dst = time.localtime(time.mktime(date_time))[8]
1844 gmtoff = -(time.timezone, time.altzone)[dst]
1845 else:
1846 gmtoff = -time.timezone
1847 delta = timedelta(seconds=gmtoff)
1848 dt = datetime(*date_time[:6], tzinfo=timezone(delta))
1849 elif isinstance(date_time, datetime):
1850 if date_time.tzinfo is None:
1851 raise ValueError("date_time must be aware")
1852 dt = date_time
1853 elif isinstance(date_time, str) and (date_time[0],date_time[-1]) == ('"','"'):
1854 return date_time # Assume in correct format
1855 else:
1856 raise ValueError("date_time not of a known type")
1857 fmt = '"%d-{}-%Y %H:%M:%S %z"'.format(Months[dt.month])
1858 return dt.strftime(fmt)
1859
1860
1861

Callers 1

appendMethod · 0.85

Calls 7

timedeltaClass · 0.90
datetimeClass · 0.90
timezoneClass · 0.90
astimezoneMethod · 0.80
fromtimestampMethod · 0.45
formatMethod · 0.45
strftimeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…