diff --git a/src/milla/util.py b/src/milla/util.py index d996821..29fbff0 100644 --- a/src/milla/util.py +++ b/src/milla/util.py @@ -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 @@ -46,4 +50,19 @@ def asbool(val): pass if val in ('false', 'no', 'f', 'n', 'off', '0'): return False - return True \ No newline at end of file + 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)