コード例 #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 search_events($searchTerms, $month=NULL, $year=NULL) {
    if ($year === NULL) {
      $year = date('Y');
    }

    if ($month === NULL) {
      $month = date('n');
    }

    $fiscal_year = ($month <= 6) ? $year : $year + 1;
    if (array_key_exists($fiscal_year, self::$icals)) {
      $ical = self::$icals[$fiscal_year];
    } else {
      return array();
    }

    // adjust day starts for time zones
    // honestly i am not 100% sure these are the right params
    $month_start = day_of(mktime(0, 0, 0, $month, 1, $year));
    $month_end = increment_month($month_start);

    $monthRange = new TimeRange($month_start, $month_end);
    //$result = array();
    //foreach (self::$icals as $ical) {
    //  $result = array_merge($result, $ical->search_events($searchTerms, $monthRange));
    //}
    $result = $ical->search_events($searchTerms, $monthRange);
    return $result;
  }
コード例 #3
0
  private static function get_next_scheduled_loop_start($routeName, $time=NULL) {
    if ($time === NULL)
      $time = time();

    $routeInfo = self::get_route_info($routeName);
    if ($routeInfo === NULL)
      return NULL;

    $interval = self::get_interval($routeName);
    $sSinceMidnight = $time - day_of($time, TIMEZONE);
    // use case for people checking saferides after midnight
    if (array_key_exists('isSafeRide', $routeInfo) && $sSinceMidnight < 5 * 3600) {
      $sSinceMidnight += 86400;
      $runsToday = self::get_runs_today($routeName, $time - 86400);
    } else {
      $runsToday = self::get_runs_today($routeName, $time);
    }

    $nextStarts = Array();
    foreach ($runsToday as $run) {
      if ($run['last'] + $interval < $sSinceMidnight)
	continue;
      $sSinceStart = $sSinceMidnight - $run['first'];

      if ($sSinceStart < 0) { // route has not started for the day
	$nextStarts[] = day_of($time, TIMEZONE) + $run['first'];
      } else if ($sSinceStart < $run['last']) {
	$nextStarts[] = $time - ($sSinceStart % $interval) + $interval;
      } // otherwise, route is done for the day
    }

    if (count($nextStarts) == 0) { // route doesn't run today, get earliest day
      for ($i = 0; $i < 7; $i++) {
	$time += 86400;
	$day = date('D', $time);
	if (array_key_exists($day, $routeInfo['runs'])) {
	  $runs = $routeInfo['runs'][$day];
	  $runStarts = Array();
	  foreach ($runs as $run) {
	    $runStarts[] = $run['first'];
	  }
	  $nextStart = day_of($time, TIMEZONE) + min($runStarts);
	  break;
	}
      }
      if ($nextStart && self::is_running_today($routeName, $time, TRUE))
	$nextStarts[] = $nextStart;
    }
    return $nextStarts;
  }
コード例 #4
0
  public function nextStartDate($time) {
    if ($this->isInService($time)) {
      while (!$this->isRunningToday($time)) {
	$time += 86400;
      }
      return day_of($time, TIMEZONE);
    }

    $date = intval(date('Ymd', $time));
    $start = FALSE;
    foreach ($this->ranges as $range) {
      if ($start === FALSE
	  || ($range->start >= $date && $range->start < $start)) {
	$start = $range->start;
      }
    }

    if ($start !== FALSE) {
      $datestr = strval($start);
      $start = mktime(0, 0, 0,
		      substr($datestr, 0, 4),
		      substr($datestr, 4, 2),
		      substr($datestr, 6, 2));
      $start = day_of($start, TIMEZONE);
    }

    return $start;
  }
コード例 #5
0
 public function next_trip_start($time)
 {
     if ($time > 100000000) {
         // is unixtime
         $midnight = day_of($time);
         $time -= $midnight;
     } else {
         $midnight = 0;
     }
     $default = NULL;
     // requires that no time spans in frequencies overlap one another
     foreach ($this->frequencies as $freq) {
         $start_time = $freq[0];
         $end_time = $freq[1];
         $result = $start_time;
         if ($end_time > $time) {
             $interval = $freq[2];
             while ($result < $time) {
                 $result += $interval;
             }
         }
         if ($default === NULL || $result < $default) {
             $default = $result;
         }
     }
     return $default + $midnight;
 }
コード例 #6
0
ファイル: GTFSReader.php プロジェクト: roycefu/MIT-Mobile-Web
  public static function routesForStop($stop_id, $time) {
    $result = array();
    $midnight = day_of(time(), TIMEZONE);
    foreach (self::$trips as $trip) {
      $offset = NULL;

      foreach ($trip->stop_times as $stop_time) {
	if ($stop_time[0] == $stop_id) {
	  $offset = $stop_time[1];
	  break;
	}
      }

      if ($offset !== NULL) {
	$next_start = $trip->nextTripStart($time);
	$next_stop_time = $next_start + $offset;
	$route_id = $trip->route_id;
	$route = self::$gtfs->getRoute($route_id);
	$result[] = array(
          $next_stop_time,
	  array(
            $trip->id,
	    $route->short_name . ' - ' . $route->long_name,
	    $trip->getService()->id,
	    ),
	  TRUE,
	  );
      }
    }

    return $result;
  }