def date_range(start_date, end_date=None, num=None, delta=None):
 if (not delta):
  return []
 if (end_date and (start_date > end_date)):
  raise Exception(u'Wait. start_date needs to be before end_date')
 if (end_date and num):
  raise Exception(u'Wait. Either specify end_date OR num')
 if ((not end_date) and (not num)):
  end_date = datetime.now()
 delta_iscron = False
 if isinstance(delta, six.string_types):
  delta_iscron = True
  cron = croniter(delta, start_date)
 elif isinstance(delta, timedelta):
  delta = abs(delta)
 l = []
 if end_date:
  while (start_date <= end_date):
   l.append(start_date)
   if delta_iscron:
    start_date = cron.get_next(datetime)
   else:
    start_date += delta
 else:
  for i in range(abs(num)):
   l.append(start_date)
   if delta_iscron:
    if (num > 0):
     start_date = cron.get_next(datetime)
    else:
     start_date = cron.get_prev(datetime)
   elif (num > 0):
    start_date += delta
   else:
    start_date -= delta
 return sorted(l)

def date_range ( start_date , end_date = None , num = None , delta = None ) : if ( not delta ) : return [ ] if ( end_date and ( start_date > end_date ) ) : raise Exception ( u'Wait. start_date needs to be before end_date' ) if ( end_date and num ) : raise Exception ( u'Wait. Either specify end_date OR num' ) if ( ( not end_date ) and ( not num ) ) : end_date = datetime . now ( ) delta_iscron = False if isinstance ( delta , six . string_types ) : delta_iscron = True cron = croniter ( delta , start_date ) elif isinstance ( delta , timedelta ) : delta = abs ( delta ) l = [ ] if end_date : while ( start_date <= end_date ) : l . append ( start_date ) if delta_iscron : start_date = cron . get_next ( datetime ) else : start_date += delta else : for i in range ( abs ( num ) ) : l . append ( start_date ) if delta_iscron : if ( num > 0 ) : start_date = cron . get_next ( datetime ) else : start_date = cron . get_prev ( datetime ) elif ( num > 0 ) : start_date += delta else : start_date -= delta return sorted ( l )
return a fixed frequency datetime index .