MCPcopy Index your code
hub / github.com/RustPython/RustPython / Time2Internaldate

Function Time2Internaldate

Lib/imaplib.py:1822–1859  ·  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

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

Callers 1

appendMethod · 0.85

Calls 8

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

Tested by

no test coverage detected