/** * Benchmarking getDays function. */ public function testGetDays() { $timerange = new TimeRange('1975-01-01', '2013-01-01'); $timerange2 = new TimeRange('2012-01-01', '2012-01-01'); $overlap_found = false; foreach ($timerange->getDays(1, TimeRange::FORWARD) as $date) { if ($timerange2->overlaps($date)) { $overlap_found = true; } } $this->assertTrue($overlap_found); }
public function getEventsInRange(TimeRange $range = null, $limit = null, $filters = null) { $events = array(); $filters = is_array($filters) ? $filters : array(); foreach ($this->events as $event) { if ($event->filterItem($filters) && $range->overlaps($event->getRange())) { $events[] = $event; } } usort($events, array($this, "sort_events")); // in some case, it doesn't work properly if we just sort $this->eventStartTimes return $events; }
public function getEvents($timeRange = null) { if ($timeRange === null) { $timeRange = new TimeRange(time()); } $dayOfTheWeek = date('w', $timeRange->get_start()); $events = array(); foreach ($this->dailyHours[$dayOfTheWeek] as $event) { if ($event->overlaps($timeRange)) { $events[] = $event; } } return $events; }
public static function formatDateRange(TimeRange $range, $dateStyle, $timeStyle) { $string = ''; if ($range instanceof DayRange) { $timeStyle = self::NO_STYLE; } $string = self::formatDate($range->get_start(), $dateStyle, $timeStyle); if ($range->get_end() && $range->get_end() != $range->get_start()) { if (date('Ymd', $range->get_start()) == date('Ymd', $range->get_end())) { $dateStyle = self::NO_STYLE; } if ($dateStyle != self::NO_STYLE || $timeStyle != self::NO_STYLE) { $string .= ($dateStyle ? ' - ' : '-') . self::formatDate($range->get_end(), $dateStyle, $timeStyle); } } return $string; }
/** * @return bool * @throws \Exception */ public function isAfterWorkingHour() { if ($this->workingHours === null) { throw new \Exception('Working hours are not set!'); } if ($this->isWorkingDay() === false) { return false; } $current = $this->dateTime->format('H:i'); $currentTime = new TwentyFourHourTime($current); return !$this->workingHours->isTimeInBetween($currentTime); }
public function overlaps(TimeRange $range) { if ($range->get_start() >= $this->end) { return FALSE; } elseif ($range->get_end() <= $this->start) { return FALSE; } else { return TRUE; } }
function occurrences(ICalEvent $event, TimeRange $range = null, $max = null) { $occurrences = array(); $time = $event->get_start(); $diff = $event->get_end() - $event->get_start(); $limitType = $this->limitType; $limit = $this->limit; $count = 0; // echo date('m/d/Y H:i:s', $time) . "<br>\n"; $time = $this->nextIncrement($time, $this->type, $this->interval); while ($time <= $range->get_end()) { // echo date('m/d/Y H:i:s', $time) . "<br>\n"; if ($limitType == 'UNTIL' && $time > $limit) { break; } $occurrence_range = new TimeRange($time, $time + $diff); if ($occurrence_range->overlaps($range)) { if ($recurrence_exception = $event->getRecurrenceException($time)) { $occurrence = clone $recurrence_exception; } else { $occurrence = clone $event; $occurrence->setRange($occurrence_range); $occurrence->clear_rrules(); $recurrence_id = strftime("%Y%m%dT%H%M%S", $time); if ($tzid = $occurrence->get_tzid()) { $recurrence_id = sprintf("TZID=%s:%s", $tzid, $recurrence_id); } $occurrence->set_attribute('RECURRENCE-ID', $recurrence_id); } $occurrences[] = $occurrence; } if ($limitType == 'COUNT' && $count < $limit) { break; } if ($count > ICalRecurrenceRule::MAX_OCCURRENCES) { break; } if (!is_null($max) && count($occurrences) >= $max) { break; } $time = $this->nextIncrement($time, $this->type, $this->interval); $count++; } return $occurrences; }
public static function count_shuttles_running($routeName, $time) { $runsToday = self::get_runs_today($routeName, $time); $midnight = day_of($time, TIMEZONE); $numshuttles = 0; foreach ($runsToday as $run) { $timeRange = new TimeRange($midnight + $run['first'], $midnight + $run['last']); if ($timeRange->contains_point($time)) $numshuttles++; } return $numshuttles; }
function formatDayTitle(ICalEvent $event) { $start = $event->get_start(); $end = $event->get_end(); if ($start != $end) { // all of acad calendar time units are in days so // we can end 23:59:00 instead of 00:00:00 next day $timeRange = new TimeRange($start, $end - 1); $dateTitle = $timeRange->format('l F j'); } else { $dateTitle = date('l F j', $start); } return $dateTitle; }