コード例 #1
0
 public function __construct($time, $tzid = NULL)
 {
     $this->start = day_of($time, $tzid);
     // define the end of the day by 11:59:59pm
     $this->end = increment_day($this->start) - 1;
 }
コード例 #2
0
  public static function get_term($time=NULL) {
    if ($time === NULL)
      $time = time();

    if (self::$terms === NULL) {
      // if we're in the second half of the year, use next year's calendar
      $year = (date('n', $time) < 7) ? date('Y', $time) : date('Y', $time) + 1;

      // start with crude lower-bound guesses for ranges
      $fall_start = mktime(0, 0, 0, 8, 15, $year-1);
      $iap_start = mktime(0, 0, 0, 1, 1, $year);
      $spring_start = mktime(0, 0, 0, 2, 1, $year);
      $summer_start = mktime(0, 0, 0, 6, 1, $year);
      $summer_end = mktime(0, 0, 0, 8, 15, $year);

      self::$terms = Array(
	'fa' => new TimeRange($fall_start, $iap_start),
	'ia' => new TimeRange($iap_start, $spring_start),
	'sp' => new TimeRange($spring_start, $summer_start),
	'su' => new TimeRange($summer_start, $summer_end),
	);

      if (array_key_exists($year, self::$icals)) {
	$ical = self::$icals[$year];
	$events = $ical->search_by_title("first day of");

	foreach ($events as $event) {
	  $event_start = increment_day($event->get_start(), -1);
	  foreach (self::$terms as $term => $range) {
	    if ($range->contains_point($event_start)) {
	      self::$terms[$term]->set_start($event_start);
	      switch ($term) {
	      case 'ia':
		self::$terms['fa']->set_end($event_start);
		break;
	      case 'sp':
		self::$terms['ia']->set_end($event_start);
		break;
	      case 'su':
		self::$terms['sp']->set_end($event_start);
		break;
	      } // switch
	      break;
	    } // if
	  } // foreach term
	} // foreach event

      } // done creating terms
    }

    foreach (self::$terms as $term => $range) {
      if ($range->contains_point($time)) {
	return $term;
	break;
      }
    }

    return NULL;
  }