コード例 #1
0
def get_busy_free_times(events, dStart, dEnd, tStart, tEnd):
    busytimes = []
    freetimes = []
    
    begin = arrow.get(dStart)
    end = arrow.get(dEnd)
    time_begin = combine_date_time(begin, arrow.get(tStart))
    time_end = combine_date_time(begin, arrow.get(tEnd))
    i = 0

    for day in arrow.Arrow.range('day',begin,end):
      busytimes_today = Agenda()
      
      for e in events[i:]:
        if same_date(day.isoformat(), e['start']):
          busytimes_today.append(Appt.from_iso_date(e['start'],e['end'],'Busy')) #using 'Busy' because we don't want private info any further
          i = i+1

      #we have all busy times for a single day now
      #lets generate free times from busy times and and append both to their respective arrays
      timeframe = Appt.from_iso_date(time_begin,time_end,"Free Time")
      freetimes.append(busytimes_today.complement(timeframe))
      busytimes.append(busytimes_today.normalized())

      #advance the day to sync with the next iteration
      time_begin = next_day(time_begin)
      time_end = next_day(time_end)


    #return this as a dict of the free and busy times
    return {"busy":busytimes, "free":freetimes}