Changeset - 2d41f5d80104
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 14 years ago 2012-02-07 20:35:21
ohnobinki@ohnopublishing.net
Add support for detecting the start and end times of a semester, which enables the correct semester to be automatically selected.
1 file changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
school.d/umich.crawl.inc
Show inline comments
 
@@ -262,48 +262,66 @@ function umich_crawl_semester(array $sch
 
	    $semester->class_add(new Course($dept . '-' . $course_id, $row[$fields['Course Title']]));
 
	  continue;
 
	}
 
      $time_end = umich_crawl_time($matches[2], $matches[3]);
 
      $time_start = umich_crawl_time($matches[1], FALSE, $time_end);
 
      /* umich defines course_slots by meeting_type. */
 
      $meeting_type = school_crawl_meeting_type(trim($row[$fields['Component']]));
 

	
 
      /*
 
       * Some information is only presented in the first row in a
 
       * listing of courses. Perform some accumulation here.
 
       */
 
      foreach (array('Instructor') as $key)
 
	if (strlen($curr_value = trim($row[$fields[$key]])))
 
	  $row_accumulation[$key] = $curr_value;
 

	
 
      $semester->section_meeting_add($dept, $course_id, trim($row[$fields['Course Title']]),
 
				     trim($row[$fields['Section']]), $synonym,
 
				     new SectionMeeting($days, $time_start, $time_end,
 
							trim($row[$fields['Location']]),
 
							$meeting_type,
 
							$row_accumulation['Instructor']),
 
				     $meeting_type,
 
				     $credit_hours);
 

	
 
      /*
 
       * If the section so far passed as being a normal section, use
 
       * its start and end dates to help determine the semester's
 
       * respective start and end dates.
 
       */
 
      $date_start_tm = strptime(trim($row[$fields['Start Date']]), '%m/%d/%Y');
 
      $date_end_tm = strptime(trim($row[$fields['End Date']]), '%m/%d/%Y');
 
      if (!empty($date_start_tm) && !empty($date_end_tm))
 
	{
 
	  $date_start = school_crawl_gmmktime($date_start_tm);
 
	  $date_end = school_crawl_gmmktime($date_end_tm);
 
	  if ($date_start > 1000000 && $date_end > 1000000)
 
	    {
 
	      $semester->time_start_set_test($date_start);
 
	      $semester->time_end_set_test($date_end);
 
	    }
 
	}
 
    }
 
}
 

	
 
/**
 
 * \brief
 
 *   Try to turn a umich-formatted time into something usable.
 
 *
 
 * \param $raw
 
 *   The raw input.
 
 * \param $xm
 
 *   FALSE or, if PM or AM was specified, 'P' for PM and 'A' for AM.
 
 * \param $before
 
 *   A time of day before which this time must be. Used generally for
 
 *   the start time of a class. The end time of a class must be parsed
 
 *   first so that the result of that calculation may be passed as the
 
 *   $before value.
 
 */
 
function umich_crawl_time($raw, $xm = FALSE, $before = '2400')
 
{
 
  $h = $raw;
 
  $m = '00';
 
  if (strlen($raw) > 2)
 
    {
 
      $h = substr($raw, 0, strlen($raw) - 2);
0 comments (0 inline, 0 general)