/**
  * Breaks down the given ordered array of event objects into dates, and
  * outputs an ordered array of two-element associative arrays in the
  * following format:
  *	key: localized UNIX timestamp of date
  *	value:
  *		['events'] => two-element associatative array broken down thus:
  *			['allday'] => all-day events occurring on this day
  *			['notallday'] => all other events occurring on this day
  *		['today'] => whether or not this date is today
  *
  * @param array                     $events Event results
  * @param Ai1ec_Abstract_Query|null $query  Current calendar page request, if
  *                                          any (null for widget)
  *
  * @return array
  */
 function get_agenda_like_date_array($events, Ai1ec_Abstract_Query $query = null)
 {
     global $ai1ec_events_helper, $ai1ec_settings;
     $dates = array();
     // Classify each event into a date/allday category
     foreach ($events as $event) {
         if (!empty($query)) {
             $event->set_request($query);
         }
         $date = $ai1ec_events_helper->gmt_to_local($event->start);
         $date = $ai1ec_events_helper->gmgetdate($date);
         $timestamp = gmmktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']);
         $exact_date = Ai1ec_Time_Utility::format_date_for_url($timestamp, $ai1ec_settings->input_date_format);
         $href_for_date = $this->create_link_for_day_view($exact_date);
         // Ensure all-day & non all-day categories are created in correct order.
         if (!isset($dates[$timestamp]['events'])) {
             $dates[$timestamp]['events'] = array('allday' => array(), 'notallday' => array());
         }
         // Add the event.
         $category = $event->allday ? 'allday' : 'notallday';
         $dates[$timestamp]['events'][$category][] = $event;
         $dates[$timestamp]['href'] = $href_for_date;
     }
     // Flag today
     $today = $ai1ec_events_helper->gmt_to_local(Ai1ec_Time_Utility::current_time());
     $today = $ai1ec_events_helper->gmgetdate($today);
     $today = gmmktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']);
     if (isset($dates[$today])) {
         $dates[$today]['today'] = true;
     }
     return $dates;
 }