Return a list of start time for each headway-based run.

    Returns:
      a sorted list of seconds since midnight, the start time of each run. If
      this trip doesn't have headways returns an empty list.
185745
def GetFrequencyStartTimes(self):
    """"""
    start_times = []
    # for each headway period of the trip
    for freq_tuple in self.GetFrequencyTuples():
      (start_secs, end_secs, headway_secs) = freq_tuple[0:3]
      # reset run secs to the start of the timeframe
      run_secs = start_secs
      while run_secs < end_secs:
        start_times.append(run_secs)
        # increment current run secs by headway secs
        run_secs += headway_secs
    return start_times
503709
def _getMyFirstDatetimeFrom(self):
        
        myStartDt = getAwareDatetime(self.repeat.dtstart, None,
                                     self.tz, dt.time.min)
        return self.__after(myStartDt, excludeCancellations=False)
852786
def stop_times(self):
    """"""
    stop_times = set()
    for trip in self.trips():
      stop_times |= trip.stop_times()
    return stop_times
626005
def get_start_and_end_time(self, ref=None):
        
        now = time.localtime(ref)

        if self.syear == 0:
            self.syear = now.tm_year
        day_start = find_day_by_weekday_offset(self.syear, self.smon, self.swday, self.swday_offset)
        start_time = get_start_of_day(self.syear, self.smon, day_start)

        if self.eyear == 0:
            self.eyear = now.tm_year
        day_end = find_day_by_weekday_offset(self.eyear, self.emon, self.ewday, self.ewday_offset)
        end_time = get_end_of_day(self.eyear, self.emon, day_end)

        now_epoch = time.mktime(now)
        if start_time > end_time:  # the period is between years
            if now_epoch > end_time:  # check for next year
                day_end = find_day_by_weekday_offset(self.eyear + 1,
                                                     self.emon, self.ewday, self.ewday_offset)
                end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
            else:
                # it s just that the start was the last year
                day_start = find_day_by_weekday_offset(self.syear - 1,
                                                       self.smon, self.swday, self.swday_offset)
                start_time = get_start_of_day(self.syear - 1, self.smon, day_start)
        else:
            if now_epoch > end_time:
                # just have to check for next year if necessary
                day_start = find_day_by_weekday_offset(self.syear + 1,
                                                       self.smon, self.swday, self.swday_offset)
                start_time = get_start_of_day(self.syear + 1, self.smon, day_start)
                day_end = find_day_by_weekday_offset(self.eyear + 1,
                                                     self.emon, self.ewday, self.ewday_offset)
                end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)

        return (start_time, end_time)
697950
def starts_within(self, start=None, end=None):
        

        qs = self

        if start:
            dt_start=coerce_dt_awareness(start)
            qs = qs.filter(
                Q(is_all_day=False, start__gte=dt_start) |
                Q(is_all_day=True, start__gte=zero_datetime(dt_start))
            )
        if end:
            dt_end=coerce_dt_awareness(end, t=time.max)
            qs = qs.filter(
                # Exclusive for datetime, inclusive for date.
                Q(is_all_day=False, start__lt=dt_end) |
                Q(is_all_day=True, start__lte=zero_datetime(dt_end))
            )

        return qs
564671
def timespan(start_time):
    """"""

    timespan = datetime.datetime.now() - start_time
    timespan_ms = timespan.total_seconds() * 1000
    return timespan_ms
995752
def durations(self) -> List[datetime.timedelta]:
        
        return [x.duration() for x in self.intervals]
776879
def start_time(self):
        
        resource_list = self.traffic_incident()
        start_time = namedtuple('start_time', 'start_time')
        if len(resource_list) == 1 and resource_list[0] is None:
            return None
        else:
            try:
                return [start_time(resource['start'])
                        for resource in resource_list]
            except (KeyError, TypeError):
                return [start_time(resource['StartTimeUTC'])
                        for resource in resource_list]
341585
def check(self):
    

    if self.value is None:
      return True
    return (time.clock() - self.start) >= self.value
1016831
def remaining_time(self):
        
        elapsed_time = (datetime.datetime.now() - self.start_time).total_seconds()
        # safety to avoid devision by zero
        if self.progress == 0:
            self.progress = 1

        estimated_total_time = 100. / self.progress * elapsed_time

        return datetime.timedelta(seconds = max(estimated_total_time - elapsed_time, 0))
1086929
def scheduledTimes(self, runnable):
        
        events = self.store.query(
            TimedEvent, TimedEvent.runnable == runnable)
        return (event.time for event in events if not event.running)
82050
def _GenerateStopTimesTuples(self):
    """"""
    stoptimes = self.GetStopTimes()
    for i, st in enumerate(stoptimes):
      yield st.GetFieldValuesTuple(self.trip_id)
952070
def _GetTimeValues(self, number_of_seconds):
    
    number_of_seconds = int(number_of_seconds)
    number_of_minutes, seconds = divmod(number_of_seconds, 60)
    number_of_hours, minutes = divmod(number_of_minutes, 60)
    number_of_days, hours = divmod(number_of_hours, 24)
    return number_of_days, hours, minutes, seconds
673526
def GetCountStopTimes(self):
    """"""
    cursor = self._schedule._connection.cursor()
    cursor.execute(
        'SELECT count(*) FROM stop_times WHERE trip_id=?', (self.trip_id,))
    return cursor.fetchone()[0]
861896
def speed(self):
        
        if not len(self) > 1:
            raise RuntimeError('More than one location is required')
        try:
            times = [i.time for i in self]
        except AttributeError:
            raise NotImplementedError('Not all Point objects include time '
                                      'attribute')

        return (distance / ((times[i + 1] - times[i]).seconds / 3600)
                for i, distance in enumerate(self.distance()))
49302
def get_start_and_end_time(self, ref=None):
        
        now = time.localtime(ref)
        if self.syear == 0:
            self.syear = now.tm_year
        month_start_id = now.tm_mon
        day_start = find_day_by_offset(self.syear, month_start_id, self.smday)
        start_time = get_start_of_day(self.syear, month_start_id, day_start)

        if self.eyear == 0:
            self.eyear = now.tm_year
        month_end_id = now.tm_mon
        day_end = find_day_by_offset(self.eyear, month_end_id, self.emday)
        end_time = get_end_of_day(self.eyear, month_end_id, day_end)

        now_epoch = time.mktime(now)

        if start_time > end_time:
            month_start_id -= 1
            if month_start_id < 1:
                month_start_id = 12
                self.syear -= 1
        day_start = find_day_by_offset(self.syear, month_start_id, self.smday)
        start_time = get_start_of_day(self.syear, month_start_id, day_start)

        if end_time < now_epoch:
            month_end_id += 1
            month_start_id += 1
            if month_end_id > 12:
                month_end_id = 1
                self.eyear += 1
            if month_start_id > 12:
                month_start_id = 1
                self.syear += 1

            # For the start
            day_start = find_day_by_offset(self.syear, month_start_id, self.smday)
            start_time = get_start_of_day(self.syear, month_start_id, day_start)

            # For the end
            day_end = find_day_by_offset(self.eyear, month_end_id, self.emday)
            end_time = get_end_of_day(self.eyear, month_end_id, day_end)

        return (start_time, end_time)
1318713
def next(self):
        '''
        
        '''
        if self.started is False:

            self.started = True
            now_ = datetime.now()
            if self.hour:
                # Fixed hour in a day
                # Next run will be the next day
                scheduled = now_.replace(hour=self.hour, minute=self.minute, second=self.second, microsecond=0)
                if scheduled == now_:
                    return timedelta(seconds=0)
                elif scheduled < now_:
                    # Scheduled time is passed
                    return scheduled.replace(day=now_.day + 1) - now_
            else:
                # Every hour in a day
                # Next run will be the next hour
                scheduled = now_.replace(minute=self.minute, second=self.second, microsecond=0)
                if scheduled == now_:
                    return timedelta(seconds=0)
                elif scheduled < now_:
                    # Scheduled time is passed
                    return scheduled.replace(hour=now_.hour + 1) - now_
            return scheduled - now_
        else:
            if self.hour:
                return timedelta(days=1)  # next day
            return timedelta(hours=1)