def timedelta_to_seconds(td):
    """
    Converts a timedelta to total seconds.
    (This is built-in in Python 2.7)
    """
    # we ignore microseconds for this
    if not td:
        return None
    return td.seconds + td.days * 24 * 3600