Back to index

moin  1.9.0~rc2
timefuncs.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Date & Time Utilities
00004 
00005     @copyright: 2003 Juergen Hermann <jh@web.de>
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 # we guarantee that time is always imported!
00010 import re, time
00011 from email.Utils import formatdate
00012 
00013 def tmtuple(tmsecs=None):
00014     """ Return a time tuple.
00015 
00016         This is currently an alias for gmtime(), but allows later tweaking.
00017     """
00018     # avoid problems due to timezones etc. - especially a underflow
00019     if -86400 <= tmsecs <= 86400: # if we are around 0, we maybe had
00020         tmsecs = 0                # 0 initially, so reset it to 0.
00021     return time.gmtime(tmsecs or time.time())
00022 
00023 def formathttpdate(tmsecs=None):
00024     """ Return a HTTP date/time stamp as defined in
00025         http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3 .
00026     """
00027     stamp = formatdate(tmsecs, False)
00028     # replace non-standard "-0000" at end with http-mandated "GMT"
00029     stamp = re.match('^(.*) [\-\+]0000$', stamp).group(1) + " GMT"
00030     return stamp
00031 
00032 def W3CDate(tmsecs=None):
00033     """ Return UTC time string according to http://www.w3.org/TR/NOTE-datetime
00034     """
00035     if not tmsecs:
00036         tmsecs = time.gmtime()
00037     return time.strftime("%Y-%m-%dT%H:%M:%S", tmsecs) + "Z"
00038