Skip to content
Snippets Groups Projects
time.py 418 B
Newer Older

from calendar import timegm
from datetime import datetime, timedelta


def to_unix_timestamp(dt):
    return int(timegm(dt.utctimetuple()))


Bruce Flynn's avatar
Bruce Flynn committed
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()