Changeset - 303e331cb53f
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 13 years ago 2012-08-30 12:18:21
ohnobinki@ohnopublishing.net
Make the Semester class smarter about guessing it start and end times based on season to support crawling without getting exact times, fixing dordt semester detection for now.
1 file changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
inc/class.semester.inc
Show inline comments
 
modified file chmod 100755 => 100644
 
@@ -326,24 +326,30 @@ class Semester
 
  public function time_end_pool_add($time_end)
 
  {
 
    $this->time_ends[] = $time_end;
 
  }
 

	
 
  public function time_end_get()
 
  {
 
    if (count($this->time_ends))
 
      {
 
        $times = filter_outliers($this->time_ends);
 
        $this->time_end = max($times);
 
      }
 
    elseif (!$this->time_end)
 
      {
 
        /* Return, but don't store, a guess. */
 
        $fourmonths = gmmktime(0, 0, 0, 5, 2012) - gmmktime(0, 0, 0, 1, 2012);
 
        return $this->time_start_get() + $fourmonths;
 
      }
 

	
 
    return $this->time_end;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Update the time_start.
 
   *
 
   * The time_start is a unix timestamp roughly estimating the time at
 
   * which a semester starts. It is used when guessing what semester a
 
   * user is interested in.
 
   *
 
@@ -387,24 +393,36 @@ class Semester
 
  public function time_start_pool_add($time_start)
 
  {
 
    $this->time_starts[] = $time_start;
 
  }
 

	
 
  public function time_start_get()
 
  {
 
    if (count($this->time_starts))
 
      {
 
        $times = filter_outliers($this->time_starts);
 
        $this->time_end = min($times);
 
      }
 
    elseif (!$this->time_start)
 
      {
 
        /* Return, but don't store, a guess. */
 
        $season_starts = array(
 
          'spring' => 0,
 
          'summer' => 5,
 
          'fall' => 8,
 
          'winter' => 12,
 
        );
 
        if (!empty($season_starts[$this->season]))
 
            return gmmktime(0, 0, 0, $season_starts[$this->season], $this->year);
 
      }
 

	
 
    return $this->time_start;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Get a semester's year.
 
   */
 
  public function year_get()
 
  {
 
    return $this->year;
 
  }
0 comments (0 inline, 0 general)