'Returns duration as hours (float)'

def get_duration(self, date=None, start_hour=8, end_hour=23):

    if date:
        if self.start:
            if ((self.start.date() < date) and (self.end.date() > date)):
                return ((start_hour - end_hour) + 1)
            else:
                if ((self.start.date() == date) and (self.end.date() > date)):
                    start = datetime(date.year, date.month, date.day, start_hour, 0, 0)
                    delta = (start - self.start)
                elif ((self.start.date() < date) and (self.end.date() == date)):
                    start = datetime(date.year, date.month, date.day, start_hour, 0, 0)
                    delta = (self.end - start)
                else:
                    delta = (self.end - self.start)
                return (float((delta.seconds // 3600)) + (float((delta.seconds % 3600)) / 3600))
        else:
            return 1
    elif (self.start and self.end):
        return (self.end - self.start)
    else:
        return 1
