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)
| 266 | return format_datetime(dt, usegmt) |
| 267 | |
| 268 | def 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 | |
| 287 | def make_msgid(idstring=None, domain=None): |
no test coverage detected
searching dependent graphs…