Finds minimum and maximum allowed dates.

@return array 0 => DateTime|null $minDate, 1 => DateTime|null $maxDate
351173
protected function extractRangeRule(Rules $rules)
	{
		$controlMin = $controlMax = null;
		foreach ($rules as $rule) {
			$branch = property_exists($rule, 'branch') ? $rule->branch : $rule->subRules;
			if (!$branch) {
				$validator = property_exists($rule, 'validator') ? $rule->validator : $rule->operation;
				if ($validator === Form::RANGE && !$rule->isNegative) {
					$ruleMinMax = $rule->arg;
				}

			} elseif ($branch) {
				$validator = property_exists($rule, 'validator') ? $rule->validator : $rule->operation;
				if ($validator === Form::FILLED && !$rule->isNegative && $rule->control === $this) {
					$ruleMinMax = $this->extractRangeRule($branch);
				}
			}

			if (isset($ruleMinMax)) {
				list($ruleMin, $ruleMax) = $ruleMinMax;
				if ($ruleMin !== null && ($controlMin === null || $ruleMin > $controlMin)) {
					$controlMin = $ruleMin;
				}
				if ($ruleMax !== null && ($controlMax === null || $ruleMax < $controlMax)) {
					$controlMax = $ruleMax;
				}
				$ruleMinMax = null;
			}
		}
		return [$controlMin, $controlMax];
	}
1264620
protected function getDates()
    {
        $date = new \DateTime ( "now" );
        $date->setTimezone ( new \DateTimeZone ( "America/Sao_Paulo" ) );

        $final = $date->format ( "Y-m-d\TH:i:s" );

        $dateInterval = "P" . ( string ) $this->_days . "D";
        $date->sub ( new \DateInterval ( $dateInterval ) );
        $date->setTime ( 00, 00, 00 );
        $initial = $date->format ( "Y-m-d\TH:i:s" );

        return [
            'initial' => $initial,
            'final'   => $final
        ];
    }
799097
function betweenDates($min, $max, $msg)
    {
        $this->minDate($min, $msg);
        $this->maxDate($max, $msg);
    }
1004830
public function whereBetween($expr, $min, $max)
    {
        if ($min === null || $min === '') {
            return $max === null || $max === '' ? $this : $this->whereCmp($expr, '<=', $max);
        } elseif ($max === null || $max === '') {
            return $min === null || $min === '' ? $this : $this->whereCmp($expr, '>=', $min);
        }

        if (strpos($expr, '[') === false && strpos($expr, '(') === false) {

            if (strpos($expr, '.') !== false) {
                $id = strtr($expr, '.', '_');
                $expr = '[' . str_replace('.', '].[', $expr) . ']';

            } else {
                $id = $expr;
                $expr = '[' . $expr . ']';
            }

            $minKey = $id . '_min';
            $maxKey = $id . '_max';
        } else {
            $minKey = '_min_' . $this->_hiddenParamNumber;
            $maxKey = '_max_' . $this->_hiddenParamNumber;
            $this->_hiddenParamNumber++;
        }

        $this->_conditions[] = "$expr BETWEEN :$minKey AND :$maxKey";

        $this->_bind[$minKey] = $min;
        $this->_bind[$maxKey] = $max;

        return $this;
    }
50703
public function getDates()
    {
        static $dates = [];

        $class = get_class($this);

        if (! isset($dates[$class])) {
            static::$dispatcher->dispatch(
                new ConfigureModelDates($this, $this->dates)
            );

            $dates[$class] = $this->dates;
        }

        return $dates[$class];
    }
703344
public function get_dates_summary() {
        $timenow = time();
        $quiz = $this->quizobj->get_quiz();

        // Exact open and close dates for the tool-tip.
        $dates = array();
        if ($quiz->timeopen > 0) {
            if ($timenow > $quiz->timeopen) {
                $dates[] = get_string('quizopenedon', 'quiz', userdate($quiz->timeopen));
            } else {
                $dates[] = get_string('quizwillopen', 'quiz', userdate($quiz->timeopen));
            }
        }
        if ($quiz->timeclose > 0) {
            if ($timenow > $quiz->timeclose) {
                $dates[] = get_string('quizclosed', 'quiz', userdate($quiz->timeclose));
            } else {
                $dates[] = get_string('quizcloseson', 'quiz', userdate($quiz->timeclose));
            }
        }
        if (empty($dates)) {
            $dates[] = get_string('alwaysavailable', 'quiz');
        }
        $explanation = implode(', ', $dates);

        // Brief summary on the page.
        if ($timenow < $quiz->timeopen) {
            $currentstatus = get_string('quizisclosedwillopen', 'quiz',
                    userdate($quiz->timeopen, get_string('strftimedatetimeshort', 'langconfig')));
        } else if ($quiz->timeclose && $timenow <= $quiz->timeclose) {
            $currentstatus = get_string('quizisopenwillclose', 'quiz',
                    userdate($quiz->timeclose, get_string('strftimedatetimeshort', 'langconfig')));
        } else if ($quiz->timeclose && $timenow > $quiz->timeclose) {
            $currentstatus = get_string('quizisclosed', 'quiz');
        } else {
            $currentstatus = get_string('quizisopen', 'quiz');
        }

        return array($currentstatus, $explanation);
    }
1150955
public function getAvailableFrom()
    {
        if ($this->AvailableFromDate) {
            return $this->dbObject('AvailableFromDate');
        } elseif ($startDate = $this->getEventStartDate()) {
            $lastWeek = new Date();
            $lastWeek->setValue(strtotime(self::config()->get('sale_start_threshold'), strtotime($startDate->value)));
            return $lastWeek;
        }

        return null;
    }
451353
public function getTopBrowsersForPeriod($startDate, $endDate, $maxResults)
    {
        $browserData = [];
        $answer = $this->performQuery($startDate, $endDate, 'ga:sessions', ['dimensions' => 'ga:browser', 'sort' => '-ga:sessions']);

        if (is_null($answer->rows)) {
            return new Collection([]);
        }

        foreach ($answer->rows as $browserRow) {
            $browserData[] = ['browser' => $browserRow[0], 'sessions' => $browserRow[1]];
        }

        $browserCollection = new Collection(array_slice($browserData, 0, $maxResults - 1));

        if (count($browserData) > $maxResults) {
            $otherBrowsers = new Collection(array_slice($browserData, $maxResults - 1));
            $otherBrowsersCount = array_sum($otherBrowsers->lists('sessions'));

            $browserCollection->put(null, ['browser' => 'other', 'sessions' => $otherBrowsersCount]);
        }

        return $browserCollection;
    }
571954
public function getDates()
    {
        $defaults = [static::CREATED_AT, static::UPDATED_AT];

        return $this->timestamps ? array_merge($this->dates, $defaults) : $this->dates;
    }
542218
public static function maxOf(LocalDate ...$dates) : LocalDate
    {
        if (! $dates) {
            throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.');
        }

        $max = LocalDate::min();

        foreach ($dates as $time) {
            if ($time->isAfter($max)) {
                $max = $time;
            }
        }

        return $max;
    }
280190
function getDaysByYear({
  minDate, maxDate, year,
}) {
  const days = [];
  const maxYear = new Date(maxDate).getFullYear();
  const minYear = new Date(minDate).getFullYear();
  const arr = [];
  const start = year - 1 >= minYear ? year - 1 : minYear;
  for (let i = 0; i <= 2; i++) {
    if (i + start <= maxYear) {
      arr.push(start + i);
    }
  }
  arr.forEach((item) => {
    for (let i = 1; i < 13; i += 1) {
      getDaysByMonth({
        minDate, maxDate, year: item, month: i - 1,
      }).forEach((el) => {
        days.push(`${item}${addZero(i)}${addZero(el.value)}` - 0);
      });
    }
  });
  return days;
}
1110040
public function getDefaultPeriod($defaultDate = null)
    {
        list($defaultDate, $defaultPeriod) = $this->getDefaultDateAndPeriod($defaultDate);

        return $defaultPeriod;
    }
647116
public function getDateRange()
    {
        $fromDate = $this->request->getParam('from', self::DEFAULT_FROM_DATE);
        if ($fromDate !== self::DEFAULT_FROM_DATE) {
            $fromDate = base64_decode($fromDate);
        }
        $toDate = $this->request->getParam('to', self::DEFAULT_TO_DATE);
        if ($toDate !== self::DEFAULT_TO_DATE) {
            $toDate = base64_decode($toDate);
        }

        $dateRange = [
            'from' => $this->createDateFromText($fromDate),
            'to'   => $this->createDateFromText($toDate),
        ];

        return $this->sortDateRange($dateRange);
    }
1221277
public function getAvailableTill()
    {
        if ($this->AvailableTillDate) {
            return $this->dbObject('AvailableTillDate');
        } elseif ($startDate = $this->getEventStartDate()) {
            $till = strtotime(self::config()->get('sale_end_threshold'), strtotime($startDate->Nice()));
            $date = SS_Datetime::create();
            $date->setValue(date('Y-m-d H:i:s', $till));
            return $date;
        }

        return null;
    }
757278
private function getDateRangeFilter(): Filter
    {
        $today = new \DateTime();
        $today = $today->setTimezone(new \DateTimeZone('UTC'));

        $todayStart = $today->format('Y-m-d H:i:s 0:0:0');
        $todayEnd = $today->format('Y-m-d H:i:s 23:59:59');

        $filterNoDateRange = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('validFrom', null),
                new EqualsFilter('validUntil', null),
            ]
        );

        $filterStartedNoEndDate = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new RangeFilter('validFrom', ['lte' => $todayStart]),
                new EqualsFilter('validUntil', null),
            ]
        );

        $filterActiveNoStartDate = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('validFrom', null),
                new RangeFilter('validUntil', ['gte' => $todayEnd]),
            ]
        );

        $activeDateRangeFilter = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new RangeFilter('validFrom', ['lte' => $todayStart]),
                new RangeFilter('validUntil', ['gte' => $todayEnd]),
            ]
        );

        $dateFilter = new MultiFilter(
            MultiFilter::CONNECTION_OR,
            [
                $filterNoDateRange,
                $filterActiveNoStartDate,
                $filterStartedNoEndDate,
                $activeDateRangeFilter,
            ]
        );

        return $dateFilter;
    }
708077
public function getExpires() {
        if (!isset($this->metadata[OSSHeaders::EXPIRES])) {
            return null;
        }
        return DateUtils::parseDate($this->metadata[OSSHeaders::EXPIRES]);
    }
764160
public function getDateTime()
    {
        if (!empty($this->parts) && $this->parts[0] instanceof DatePart) {
            return $this->parts[0]->getDateTime();
        }
        return null;
    }