Added http_date utility function

master
Dustin C. Hatch 2012-11-19 17:29:04 -06:00
parent b50ca751fb
commit dd05d95dba
1 changed files with 20 additions and 1 deletions

View File

@ -21,6 +21,10 @@ Please give me a docstring!
:Updater: $Author$
'''
from wsgiref.handlers import format_date_time
import datetime
import time
def asbool(val):
'''Test a value for truth
@ -47,3 +51,18 @@ def asbool(val):
if val in ('false', 'no', 'f', 'n', 'off', '0'):
return False
return True
def http_date(date):
'''Format a datetime object as a string in RFC 1123 format
This function returns a string representing the date according to
RFC 1123. The string returned will always be in English, as
required by the specification.
:param date: A :py:class:`datetime.datetime` object
:return: RFC 1123-formatted string
'''
stamp = time.mktime(date.timetuple())
return format_date_time(stamp)