Newer
Older
from calendar import timegm
from datetime import datetime, timedelta
def to_unix_timestamp(dt):
return int(timegm(dt.utctimetuple()))
def hhmm_to_offset(hhmm):
"""Convert a string time, possibly with missing hours and minutes, to an
offset of seconds.
"""
hhmm = '{:04d}'.format(int(hhmm))
return timedelta(hours=int(hhmm[0:2]),
minutes=int(hhmm[2:])).total_seconds()