needed new function

This commit is contained in:
Roland Hedberg
2010-09-28 13:35:06 +02:00
parent 5a699d11c9
commit 789943fc3c

View File

@@ -234,6 +234,20 @@ def a_while_ago(days=0, seconds=0, microseconds=0, milliseconds=0,
# ---------------------------------------------------------------------------
def shift_time(dtime, shift):
""" Adds/deletes an integer amount of seconds from a datetime specification
:param dtime: The datatime specification
:param shift: The wanted time shift (+/-)
:return: A shifted datatime specification
"""
tstruct = dtime.timetuple()
tfl = time.mktime(tstruct)
tfl += shift
return datetime.utcfromtimestamp(tfl)
# ---------------------------------------------------------------------------
def str_to_time(timestr):
if not timestr:
return 0