def time_to_offset(starttime, endtime, middletime):
    """Transform middle time to offset."""
    nominator = (middletime - starttime).total_seconds()
    denominator = (endtime - starttime).total_seconds()
    return float(nominator) / float(denominator)