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

Function format_datetime

Lib/email/utils.py:268–284  ·  view source on GitHub ↗

Turn a datetime into a date string as specified in RFC 2822. If usegmt is True, dt must be an aware datetime with an offset of zero. In this case 'GMT' will be rendered instead of the normal +0000 required by RFC2822. This is to support HTTP headers involving date stamps.

(dt, usegmt=False)

Source from the content-addressed store, hash-verified

266 return format_datetime(dt, usegmt)
267
268def format_datetime(dt, usegmt=False):
269 """Turn a datetime into a date string as specified in RFC 2822.
270
271 If usegmt is True, dt must be an aware datetime with an offset of zero. In
272 this case 'GMT' will be rendered instead of the normal +0000 required by
273 RFC2822. This is to support HTTP headers involving date stamps.
274 """
275 now = dt.timetuple()
276 if usegmt:
277 if dt.tzinfo is None or dt.tzinfo != datetime.timezone.utc:
278 raise ValueError("usegmt option requires a UTC datetime")
279 zone = 'GMT'
280 elif dt.tzinfo is None:
281 zone = '-0000'
282 else:
283 zone = dt.strftime("%z")
284 return _format_timetuple_and_zone(now, zone)
285
286
287def make_msgid(idstring=None, domain=None):

Callers 1

formatdateFunction · 0.85

Calls 3

timetupleMethod · 0.45
strftimeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…