def _subdivide_interval_by_hour(start, end):
 start_hour = start.replace(minute=0, second=0, microsecond=0)
 end_hour = end.replace(minute=0, second=0, microsecond=0)
 if (start_hour == end_hour):
  hour_to_secs = {start_hour: _to_secs((end - start))}
 else:
  hour_to_secs = {}
  hour_to_secs[start_hour] = _to_secs(((start_hour + timedelta(hours=1)) - start))
  hour_to_secs[end_hour] = _to_secs((end - end_hour))
  cur_hour = (start_hour + timedelta(hours=1))
  while (cur_hour < end_hour):
   hour_to_secs[cur_hour] = _to_secs(timedelta(hours=1))
   cur_hour += timedelta(hours=1)
 hour_to_secs = dict(((h, secs) for (h, secs) in hour_to_secs.items() if secs))
 return hour_to_secs

def _subdivide_interval_by_hour ( start , end ) : start_hour = start . replace ( minute = 0 , second = 0 , microsecond = 0 ) end_hour = end . replace ( minute = 0 , second = 0 , microsecond = 0 ) if ( start_hour == end_hour ) : hour_to_secs = { start_hour : _to_secs ( ( end - start ) ) } else : hour_to_secs = { } hour_to_secs [ start_hour ] = _to_secs ( ( ( start_hour + timedelta ( hours = 1 ) ) - start ) ) hour_to_secs [ end_hour ] = _to_secs ( ( end - end_hour ) ) cur_hour = ( start_hour + timedelta ( hours = 1 ) ) while ( cur_hour < end_hour ) : hour_to_secs [ cur_hour ] = _to_secs ( timedelta ( hours = 1 ) ) cur_hour += timedelta ( hours = 1 ) hour_to_secs = dict ( ( ( h , secs ) for ( h , secs ) in hour_to_secs . items ( ) if secs ) ) return hour_to_secs
convert a time interval to a map from hours to the number of seconds during that hour that are within the interval *start* and *end* are :py:class:datetime .