view MoinMoin/util/datetime.py @ 15:5a2a8201bb6f

make moin friendlier to proxies, thanks to ASF imported from: moin--main--1.5--patch-16
author Thomas Waldmann <tw@waldmann-edv.de>
date Fri, 23 Sep 2005 20:02:07 +0000
parents 77665d8e2254
children
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - Date & Time Utilities

    @copyright: 2003 by Jürgen Hermann <jh@web.de>
    @license: GNU GPL, see COPYING for details.
"""

# we guarantee that time is always imported!
import time
import re
from email.Utils import formatdate

def tmtuple(tmsecs=None):
    """ Return a time tuple.

        This is currently an alias for gmtime(), but allows later tweaking.
    """
    # avoid problems due to timezones etc. - especially a underflow
    if -86400 <= tmsecs <= 86400: # if we are around 0, we maybe had
        tmsecs = 0                # 0 initially, so reset it to 0.
    return time.gmtime(tmsecs or time.time())

def formathttpdate(tmsecs=None):
    """ Return a HTTP date/time stamp as defined in
        http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3 .
    """
    stamp = formatdate(tmsecs, False)
    # replace non-standard "-0000" at end with http-mandated "GMT"
    stamp = re.match('^(.*) [\-\+]0000$', stamp).group(1) + " GMT"
    return stamp