Interval between two hours
@param  string  $start    01:00:00
@param  string  $end      23:00:00
@param  integer $interval Interval in hours
@param  boolean $select   For use in select of a form or array only
@return array
499598
public function rangeHours($start, $end, $interval = 1, $select = true)
    {
        $tStart = strtotime($start);
        $tEnd = strtotime($end);
        $tNow = $tStart;

        $hours = [];
        while ($tNow <= $tEnd) {
            $hours[] = date("H:i", $tNow);
            $tNow = strtotime('+'.$interval.' hour', $tNow);
        }

        if ($select) {
            $hours = collect($hours)->map(function ($item) {
                return [
                    $item => $item
                ];
            })->collapse()->all();
        }

        return $hours;
    }
599773
public static function getDateTimeRange($start, $end = null, $exact = false)
    {
        return [
            static::buildDateTime($start, !$exact),
            static::buildDateTime($end ?: $start, false, !$exact),
        ];
    }
374534
public static function getRangeTime( $start, $end, $dec = 6 )
	{
		if( !isset( self::$info[$end] ) ){
			self::$info[$end] = microtime( true );
		}
		return number_format( (self::$info[$end] - self::$info[$start]), $dec );
	}
678133
public function setInterval( $start, $end )
	{
		if( $start * $end > 0 )
			throw new InvalidArgumentException( 'Interval needs to start below 0.' );
		$this->interval	= new Alg_Math_CompactInterval( $start, $end );
	}
840335
function range(begin, end) {
  var interval = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2];

  var a = [];

  for (var i = begin; i < begin + end; i += interval) {
    a.push(i);
  }

  return a;
}
170568
final public static function formatInterval($interval, $parts = 0)
    {
        $interval = self::recalculateInterval($interval);

        $format = [];
        if ($interval->y !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{y,plural,one{# year} few{# years} many{# years} other{# years}}',
                ['y' => $interval->y]
            );
        }

        if ($interval->m !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{m,plural,one{# month} few{# months} many{# months} other{# months}}',
                ['m' => $interval->m]
            );
        }

        if ($interval->d !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{d,plural,one{# day} few{# days} many{# days} other{# days}}',
                ['d' => $interval->d]
            );
        }

        if ($interval->h !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{h,plural,one{# hour} few{# hours} many{# hours} other{# hours}}',
                ['h' => $interval->h]
            );
        }

        if ($interval->i !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{i,plural,one{#minute} few{# minutes} many{# minutes} other{# minutes}}',
                ['i' => $interval->i]
            );
        }

        if ($interval->s !== 0) {
            $format[] = Yii::t(
                'datetime',
                '{s,plural,one{# second} few{# seconds} many{# seconds} other{# seconds}}',
                ['s' => $interval->s]
            );
        }

        if (count($format) === 0) {
            return "";
        }

        if (($parts > 0) && (count($format) > 1)) {
            $values = [];
            while ((count($values) < $parts) && (count($format) > 0)) {
                $values[] = array_shift($format);
            }
        } else {
            $values = $format;
        }

        return implode(" ", $values);
    }
1214852
private static function getValidCellRange($startRow, $startColumn, $endRow, $endColumn)
    {
        if ($endRow === null) {
            $endRow = $startRow;
        }
        elseif ($startRow > $endRow) {
            $temp = $startRow;
            $startRow = $endRow;
            $endRow = $temp;
        }

        if ($endColumn === null) {
            $endColumn = $startColumn;
        }
        elseif ($startColumn > $endColumn) {
            $temp = $startColumn;
            $startColumn = $endColumn;
            $endColumn = $temp;
        }

        return array($startRow, $startColumn, $endRow, $endColumn);
    }
36594
public static SimpleInterval<Date> between(
        Date start,
        Date end
    ) {

        return OLD_DATE_FACTORY.between(start, end);

    }
760201
private function intervalToSeconds(DateInterval $interval): int
    {
        $seconds = (int) $interval->format('%s');

        $multiplier = 60;
        $seconds += (int) $interval->format('%i') * $multiplier;

        $multiplier *= 60;
        $seconds += (int) $interval->format('%h') * $multiplier;

        $multiplier *= 24;
        $seconds += (int) $interval->format('%d') * $multiplier;

        $multiplier *= 30;
        $seconds += (int) $interval->format('%m') * $multiplier;

        $multiplier *= 12;
        $seconds += (int) $interval->format('%y') * $multiplier;

        return $seconds;
    }
712848
public function lgetrange($key, $start, $end)
    {
        try {
            return $this->redis->lgetrange($key, $start, $end);
        } catch (\RedisException $e) {
            die("Error!: " . $e->getMessage() . "<br/>");
        }
    }
417010
private final function prepInterval( array $interval, &$error = null )
    {

        $error = null;

        if( $interval === array('') ) {
            return null;
        }

        if( $interval === array(null) ) {
            $this->containsNull = true;
            return null;
        }

        // cast interval to correct type
        foreach( $interval as &$value ) {
            if( !$this->cast( $value, $error ) ) {
                return null;
            }
        }

        switch( count( $interval ) ) {

            case 1:
                $interval[1] = $interval[0];
                break;

            case 2:

                if( $interval[0] !== null and $interval[1] !== null ) {
                    usort( $interval, array( $this, 'sort' ) );
                }
                break;

            default:
                $error = "too many fragments";
                return null;

        }

        return $interval;

    }
1155235
private function get_interval(string $interval = '')
  {
    if ( !empty($interval) ){
      $this->interval = new \DateInterval($interval);
      return $this->interval;
    }
    else {
      return $this->interval;
    }
  }
511351
public function getStartTimes($starttime = 0, $endtime = 0, $tz = null) {
		if (!Util::isValidTimezone($tz)) {
			$tz = Util::getClientTimezone();
		}

		if (!$this->isRecurring()) {
			return array($this->getStartTimestamp());
		}

		$start_times = array();

		$test_day = ($this->getStartTimestamp() > $starttime) ? $this->getStartTimestamp() : $starttime;

		// iterate through each day of our range and see if this event shows up on any of those days
		while ($test_day < $endtime) {

			$shows = false;

			$offset_on_test_day = Util::getOffset($test_day, Util::UTC, $this->getTimezone());

			// next increment
			$next_test_day = $test_day + Util::SECONDS_IN_A_DAY;

			// event has no more occurrences after this day
			if ($this->repeat_end_timestamp && $this->repeat_end_timestamp < $test_day) {
				break;
			}

			switch ($this->repeat_frequency) {
				case Util::FREQUENCY_DAILY:
					$shows = true;
					break;

				case Util::FREQUENCY_WEEKDAY:
					$repeat_weekly_days = array(Util::SATURDAY, Util::SUNDAY);
					foreach ($repeat_weekly_days as $key => $day) {
						$repeat_weekly_days[$key] = Util::getDayOfWeek(strtotime($day, $test_day) - $offset_on_test_day);
					}
					$D = Util::getDayOfWeek($test_day);
					$shows = !in_array($D, $repeat_weekly_days);
					break;

				case Util::FREQUENCY_WEEKDAY_ODD:
					$repeat_weekly_days = array(Util::MONDAY, Util::WEDNESDAY, Util::FRIDAY);
					foreach ($repeat_weekly_days as $key => $day) {
						$repeat_weekly_days[$key] = Util::getDayOfWeek(strtotime($day, $test_day) - $offset_on_test_day);
					}
					$D = Util::getDayOfWeek($test_day);
					$shows = in_array($D, $repeat_weekly_days);
					break;

				case Util::FREQUENCY_WEEKDAY_EVEN:
					$repeat_weekly_days = array(Util::TUESDAY, Util::THURSDAY);
					foreach ($repeat_weekly_days as $key => $day) {
						$repeat_weekly_days[$key] = Util::getDayOfWeek(strtotime($day, $test_day) - $offset_on_test_day);
					}
					$D = Util::getDayOfWeek($test_day);
					$shows = in_array($D, $repeat_weekly_days);
					break;

				case Util::FREQUENCY_WEEKLY:
					$repeat_weekly_days = $this->repeat_weekly_days;
					if (!$repeat_weekly_days) {
						$repeat_weekly_days = Util::getDayOfWeek($this->getStartTimestamp());
					}
					if (!is_array($repeat_weekly_days)) {
						$repeat_weekly_days = array($repeat_weekly_days);
					}
					$D = Util::getDayOfWeek($test_day);
					foreach ($repeat_weekly_days as $key => $day) {
						// Monday in Sydney can still be Sunday at UTC
						$repeat_weekly_days[$key] = Util::getDayOfWeek(strtotime($day, $test_day) - $offset_on_test_day);
					}
					$shows = in_array($D, $repeat_weekly_days);
					break;

				case Util::FREQUENCY_MONTHLY:
					if ($this->repeat_monthly_by == Util::REPEAT_MONTHLY_BY_DAY_OF_WEEK) {
						$shows = Util::isOnSameWeekDayOfMonth($test_day, $this->getStartTimestamp());
						if ($shows) {
							// we can skip 4 weeks
							$next_test_day = strtotime('+28 days', $test_day);
						}
					} else {
						$shows = Util::isOnSameDayOfMonth($test_day, $this->getStartTimestamp());
						if ($shows) {
							// we can skip a month
							$next_test_day = strtotime('+1 month', $test_day);
						}
					}
					break;

				case Util::FREQUENCY_YEARLY:
					$shows = Util::isOnSameDayOfYear($test_day, $this->getStartTimestamp());
					if ($shows) {
						// we can skip a year
						$next_test_day = strtotime('+1 year', $test_day);
					}
					break;
			}

			if ($shows) {
				$occurrence = (int) Util::getTimeOfDay($this->getStartTimestamp(), $test_day);
				if ($occurrence >= $starttime && $occurrence <= $endtime) {
					// events may show on a start or end day, but not fall in the time range
					array_push($start_times, $occurrence);
				}
			}

			$test_day = $next_test_day;
		}

		$cancelled = $this->cancelled_instance;
		if (!$cancelled) {
			$cancelled = array();
		}
		if (!is_array($cancelled)) {
			$cancelled = array($cancelled);
		}

		return array_diff($start_times, $cancelled);
	}
613675
public function getrange($key, $start, $end) {
        return $this->returnCommand(['GETRANGE'], $key, [$key, $start, $end]);
    }
50347
function Interval(sourceString, startIdx, endIdx) {
  this.sourceString = sourceString;
  this.startIdx = startIdx;
  this.endIdx = endIdx;
}
1000582
public function activeRangesBetween($start, $end)
    {
        $occurrences = array();
        $dh = \Core::make('date');

        $start_date = $this->getStartDate();
        $end_date = $this->getEndDate();
        if (!$end_date) {
            $end_date = $this->getStartDate();
        }

        $repetition_start = (new \DateTime($start_date, $this->getTimezone()))->getTimestamp();
        $repetition_end = (new \DateTime($end_date, $this->getTimezone()))->getTimestamp();
        $repetition_final = null;

        if ($this->getRepeatPeriodEnd()) {
            $repetition_final = (new \DateTime($this->getRepeatPeriodEnd(), $this->getTimezone()))->getTimestamp();
        }

        $repetition_num = $this->getRepeatEveryNum();

        if ($repetition_start > $start) {
            $start = $repetition_start;
        }

        if ($repetition_final && $end > $repetition_final) {
            $end = strtotime('+1 day', $repetition_final);
        }

        if ($start > $end) {
            return $occurrences;
        }

        if (!$this->repeats()) {
            if ($repetition_start >= $start && $repetition_start <= $end) {
                $occurrences[] = array($repetition_start, $repetition_end);
            }
        } else {

            switch ($this->getRepeatPeriod()) {

                case $this::REPEAT_DAILY:
                    $today = floor($start / 86400);
                    $repetition_day = floor($repetition_start / 86400);

                    if ($repetition_day > $today) {
                        $today = $repetition_day;
                    }

                    if ($repetition_difference = ($today - $repetition_day) % $repetition_num) {
                        $today -= $repetition_difference;
                        $today += $repetition_num;
                    }

                    $day_difference = $today - $repetition_day;

                    $current_date = new \DateTime();
                    $current_date->setTimezone($this->getTimezone());
                    $current_date->setTimestamp($repetition_start);
                    $current_date->modify("+{$day_difference} days");
                    $current_date_timestamp = $current_date->getTimestamp();

                    while ($current_date_timestamp < $end) {
                        $occurrences[] = array(
                            $current_date_timestamp,
                            $current_date_timestamp + $repetition_end - $repetition_start
                        );

                        $current_date->modify("+{$repetition_num} days");
                        $current_date_timestamp = $current_date->getTimestamp();
                    }

                    break;

                case $this::REPEAT_WEEKLY:
                    $start_time = new \DateTime();
                    $start_time->setTimezone($this->getTimezone());
                    $start_time->setTimestamp($start);
                    if ($start_time->format('w') != 0) {
                        $start_time->modify('last sunday');
                    }

                    $repetition_start_time = new \DateTime();
                    $repetition_start_time->setTimezone($this->getTimezone());
                    $repetition_start_time->setTimestamp($repetition_start);

                    $diff = $start_time->diff($repetition_start_time);
                    if ($difference = (floor($diff->days / 7) % $repetition_num)) {
                        $interval = \DateInterval::createFromDateString("{$difference} weeks");
                        $start_time->add($interval);
                    }

                    $current_date = new \DateTime(
                        $start_time->format('Y-m-d') . ' ' . $repetition_start_time->format('H:i:s'),
                        $this->getTimezone()
                    );
                    $current_date_timestamp = $current_date->getTimestamp();

                    while ($current_date_timestamp < $end) {
                        foreach ($this->getRepeatPeriodWeekDays() as $day) {

                            $ts = new \DateTime();
                            $ts->setTimestamp($current_date_timestamp);
                            $ts->setTimezone($this->getTimezone());
                            $ts->modify("+{$day} days");
                            $day_of_the_week = $ts->getTimestamp();

                            if ($day_of_the_week >= $start && $day_of_the_week <= $end) {
                                $occurrences[] = array(
                                    $day_of_the_week,
                                    $day_of_the_week + $repetition_end - $repetition_start,
                                );
                            }
                        }

                        $current_date->modify("+{$repetition_num} weeks");
                        $current_date_timestamp = $current_date->getTimestamp();
                    }

                    break;

                case $this::REPEAT_MONTHLY:
                    $start_time = new \DateTime();
                    $start_time->setTimezone($this->getTimezone());
                    $start_time->setTimestamp($start);

                    $start_datetime = new \DateTime($start_time->format('Y-m-01 H:i:s'), $this->getTimezone());
                    $repetition_start_datetime = new \DateTime();
                    $repetition_start_datetime->setTimezone($this->getTimezone());
                    $repetition_start_datetime->setTimestamp($repetition_start);

                    $diff = $repetition_start_datetime->diff($start_datetime);

                    if ($remainder = (($diff->m + ($diff->y * 12)) % $repetition_num)) {
                        $start_datetime->add(\DateInterval::createFromDateString("{$remainder} months"));
                    }

                    $interval = \DateInterval::createFromDateString("{$repetition_num} months");

                    $current_datetime = new \DateTime();
                    $current_datetime->setTimezone($this->getTimezone());
                    $current_datetime->setTimestamp($start_datetime->getTimestamp());

                    switch ($this->getRepeatMonthBy()) {

                        case $this::MONTHLY_REPEAT_WEEKLY:
                            $dotw = $repetition_start_datetime->format('l');
                            $wotm = -1;
                            $month = $repetition_start_datetime->format('m');
                            $wotm_step = $repetition_start_datetime->getTimestamp();

                            do {
                                ++$wotm;
                                $wotm_step = strtotime('-1 week', $wotm_step);
                                $tmp = new \DateTime();
                                $tmp->setTimestamp($wotm_step);
                                $tmp->setTimezone($this->getTimezone());
                                $wotm_step_month = $tmp->format('m');
                            } while ($wotm_step_month === $month);

                            $last_datetime = null;
                            while ($current_datetime->getTimestamp() < $end) {

                                $occurrence_start_date = clone $current_datetime;
                                $occurrence_start_date->setTimezone($this->getTimezone());
                                if ($current_datetime->format('l') != $dotw) {
                                    $occurrence_start_date->modify("next {$dotw}");
                                }

                                $occurrence_start_date->modify("+{$wotm} weeks");

                                $occurrence_start_time = new \DateTime();
                                $occurrence_start_time->setTimestamp($repetition_start);
                                $occurrence_start_time->setTimezone($this->getTimezone());

                                $occurrence_start = new \DateTime(
                                    $occurrence_start_date->format('Y-m-d ') .
                                    $occurrence_start_time->format('H:i:s'),
                                    $this->getTimezone()
                                );

                                $occurrence_start_timestamp = $occurrence_start->getTimestamp();

                                if ($occurrence_start_timestamp >= $start && $occurrence_start_timestamp <= $end) {
                                    if ($occurrence_start->format('m') === $current_datetime->format('m')) {
                                        $occurrences[] = array(
                                            $occurrence_start_timestamp,
                                            $occurrence_start_timestamp + $repetition_end - $repetition_start,
                                        );
                                    }
                                }

                                $last_datetime = clone $current_datetime;
                                $current_datetime->add($interval);
                            }
                            break;

                        case $this::MONTHLY_REPEAT_MONTHLY:
                            $current_datetime = clone $start_datetime;
                            $dotm = $repetition_start_datetime->format('j');
                            $time = $repetition_start_datetime->format('H:i:s');

                            while ($current_datetime->getTimestamp() < $end) {

                                $occurrence_start_date_time = new \DateTime();
                                $occurrence_start_date_time->setTimezone($this->getTimezone());
                                $occurrence_start_date_time->setTimestamp($current_datetime->getTimestamp());
                                $occurrence_start = $occurrence_start_date_time->format("Y-m-{$dotm} {$time}");

                                $occurrence_start = new \DateTime($occurrence_start, $this->getTimezone());
                                $occurrence_start = $occurrence_start->getTimestamp();

                                if ($occurrence_start && $occurrence_start >= $start && $occurrence_start <= $end) {
                                    $occurrences[] = array(
                                        $occurrence_start,
                                        $occurrence_start + $repetition_end - $repetition_start,
                                    );
                                }

                                $current_datetime->add($interval);
                            }
                            break;

                        case $this::MONTHLY_REPEAT_LAST_WEEKDAY:
                            $current_datetime = clone $start_datetime;
                            $weekday = $this->getDayString($this->getRepeatMonthLastWeekday());

                            while ($current_datetime->getTimestamp() < $end) {
                                $occurrence_start = $current_datetime->getTimestamp();

                                $occurrence_start_date_time1 = new \DateTime();
                                $occurrence_start_date_time1->setTimestamp($occurrence_start);
                                $occurrence_start_date_time1->setTimezone($this->getTimezone());
                                $date1 = $occurrence_start_date_time1->format('F Y');

                                $occurrence_start_date_time2 = new \DateTime();
                                $occurrence_start_date_time2->setTimestamp($occurrence_start);
                                $occurrence_start_date_time2->setTimezone($this->getTimezone());
                                $occurrence_start_date_time2->modify('Last ' . $weekday . ' of ' . $date1);

                                $occurrence_start = $occurrence_start_date_time2->format('Y-m-d ') .
                                    $repetition_start_datetime->format('H:i:s');

                                $occurrence_start = new \DateTime($occurrence_start, $this->getTimezone());
                                $occurrence_start = $occurrence_start->getTimestamp();

                                if ($occurrence_start >= $start && $occurrence_start <= $end) {
                                    $occurrences[] = array(
                                        $occurrence_start,
                                        $occurrence_start + $repetition_end - $repetition_start,
                                    );
                                }

                                $last_datetime = clone $current_datetime;
                                $current_datetime->add($interval);
                            }
                            break;
                    }

            }
        }

        return $occurrences;
    }
1324268
public static function getDayRangeInBetweenDate($startDateTime, $endDateTime, $sort = false, $format = 'Y-m-d')
    {
        $startDateTime = self::getTimestamp($startDateTime);
        $endDateTime = self::getTimestamp($endDateTime);
        $num = ($endDateTime - $startDateTime) / 86400;
        $arr = [];
        for ($i = 0; $i <= $num; $i++) {
            $arr [] = date($format, $startDateTime + 86400 * $i);
        }
        return $sort ? array_reverse($arr) : $arr;
    }