Returns a list of offsets and dates in a 24 hour period

@param *string $format   The format of each date to display
@param int     $interval The frequency of rows

@return array
13258
public function getOffsetDates($format, $interval = 30)
    {
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string')
            //argument 2 must be an integer
            ->test(2, 'int');

        $dates = array();
        $interval *= 60;

        for ($i=-12*3600; $i <= (12*3600); $i+=$interval) {
            $time = $this->time + $i;
            $dates[$i] = date($format, $time);
        }

        return $dates;
    }
77452
public function format(string $format): string
    {
        $hours = $this->getHours();
        $minutes = $this->getMinutes();
        $seconds = $this->getSeconds();

        $replace = [
            "%h"    =>  $hours,
            "%H"    =>  sprintf("%02s", $hours),
            "%m"    =>  $minutes,
            "%M"    =>  sprintf("%02s", $minutes),
            "%s"    =>  $seconds,
            "%S"    =>  sprintf("%02s", $seconds),
        ];

        return str_replace(array_keys($replace), array_values($replace), $format);
    }
889113
protected function find_intervals($interval)
    {
        if ($interval instanceof RangeInterface) {
            $first = $interval->getStart();
            $last = $interval->getEnd();
        } else {
            $first = $interval;
            $last = null;
        }

        if (null === $last) {
            $result = $this->point_search($this->top_node, $first);
        } else {
            $result = array();
            foreach ($interval->iterable() as $j) {
                $result = array_merge($result, $this->find_intervals($j));
            }
        }

        return $result;
    }
180177
public function getProcuredAt($format = 'Y-m-d')
    {
        if ($this->procuredAt instanceof \DateTime && $format !== null) {
            return $this->procuredAt->format($format);
        }

        return $this->procuredAt;
    }
548315
public static function format_retention_period(\DateInterval $interval) : string {
        // It is one or another.
        if ($interval->y) {
            $formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
        } else if ($interval->m) {
            $formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
        } else if ($interval->d) {
            $formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
        } else {
            $formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
        }

        return $formattedtime;
    }
190186
public function getTime(?int $format = null): float
    {
        $result = $this->endTime - $this->startTime;

        return $this->formatTime($result, $format);
    }
681352
public static function DateFormat($format, $date = null)
  {
    if (!empty($date) && !is_int($date)) {
      $date = strtotime($date);
    }

    return strftime($format, $date ?: time());
  }
1222774
public function findPages(Range $interval): ?Result
	{
		$builder = $this->builder()
			->select('[page], SUM([visits]) visits, SUM([views]) views')
			->andWhere('DATE([datefield]) BETWEEN DATE(%dt) AND DATE(%dt)', $interval->from, $interval->to)
			->groupBy('[page]')
			->addOrderBy('[visits] DESC, [views] DESC, [page]');
		return $this->execute($builder);
	}
341197
public static function getRunDates($time, $count = 10)
    {
        try {
            $cron = CronExpression::factory($time);
            $dates = $cron->getMultipleRunDates($count);
        } catch (\Exception $e) {
            return array();
        }
        return $dates;
    }
957744
public function getPeriod($period, $mode = self::DAYS_ONLY)
    {
        $result = $this->parsePeriod($period);

        if ($result['max'] && $mode == self::DAYS_AND_TIME) {
            $result['max']->modify("+1 day -1 second");
        }

        foreach ($result as $key => $value) {
            if (!$value) {
                unset($result[$key]);
            } elseif ($mode == self::DAYS_ONLY) {
                $result[$key] = new DateTime($result[$key]->format('Y-m-d'), $this->getTimezoneTo());
            } elseif ($this->getTimezoneTo()) {
                $result[$key]->setTimezone($this->getTimezoneTo());
            }
        }

        return $result;
    }
283977
public function getDateSunday($format = 'Y-m-d')
    {
        $weekDay = 7 - $this->format('N');
        $time = $this->getTimestamp();
        if ($weekDay) {
            $time += $weekDay * 24 * 3600;
        }
        return date($format, $time);
    }
1138768
protected function dateIntervalToSeconds($interval): int
    {
        $now = time();
        $dt = new \DateTime();
        $dt->add($interval);
        $ts = $dt->getTimestamp();
        $diff = $ts - $now;
        return $diff;
    }
1154278
public static function startOf($interval, \DateTime $date = null) {
			$date = $date ?: new \DateTime();

			switch ($interval) {
				case self::INTERVAL_MINUTE:
					$date->setTime((int)$date->format('H'), (int)$date->format('i'), 0, 0);

					break;

				case self::INTVERAL_HOUR:
					$date->setTime((int)$date->format('H'), 0, 0, 0);

					break;

				case self::INTERVAL_DAY:
					$date->setTime(0, 0, 0, 0);

					break;

				case self::INTERVAL_WEEK:
					$date
						->sub(new \DateInterval('P' . (int)$date->format('w') . 'D'))
						->setTime(0, 0, 0, 0);

					break;

				case self::INTERVAL_MONTH:
					$date
						->sub(new \DateInterval('P' . ((int)$date->format('d') - 1) . 'D'))
						->setTime(0, 0, 0, 0);

					break;

				case self::INTERVAL_YEAR:
					$date
						->setTime(0, 0, 0, 0)
						->setDate((int)$date->format('Y'), 1, 1);

					break;

				default:
					throw new \InvalidArgumentException('$interval must be one of the INTERVAL_* class constants');
			}

			return $date;
		}
234796
protected function convertDateFormatToMoment($format)
    {
        $replacements = [
            'd' => 'DD',
            'D' => 'ddd',
            'j' => 'D',
            'l' => 'dddd',
            'N' => 'E',
            'S' => 'o',
            'w' => 'e',
            'z' => 'DDD',
            'W' => 'W',
            'F' => 'MMMM',
            'm' => 'MM',
            'M' => 'MMM',
            'n' => 'M',
            't' => '', // no equivalent
            'L' => '', // no equivalent
            'o' => 'YYYY',
            'Y' => 'YYYY',
            'y' => 'YY',
            'a' => 'a',
            'A' => 'A',
            'B' => '', // no equivalent
            'g' => 'h',
            'G' => 'H',
            'h' => 'hh',
            'H' => 'HH',
            'i' => 'mm',
            's' => 'ss',
            'u' => 'SSS',
            'e' => 'zz', // deprecated since version 1.6.0 of moment.js
            'I' => '', // no equivalent
            'O' => '', // no equivalent
            'P' => '', // no equivalent
            'T' => '', // no equivalent
            'Z' => '', // no equivalent
            'c' => '', // no equivalent
            'r' => '', // no equivalent
            'U' => 'X',
        ];

        foreach ($replacements as $from => $to) {
            $replacements['\\' . $from] = '[' . $from . ']';
        }

        return strtr($format, $replacements);
    }
746779
public static function modifyNow($interval, $format = self::DEFAULT_TIME_FORMAT)
    {
        return Clock::now()->toDateTime()->modify($interval)->format($format);
    }
1087450
public function getTime(string $format = null)
    {
        $time = $this->time + $this->offset;

        if (!is_null($format)) {
            return date($format, $time);
        }

        return $time;
    }
1255673
public static function selectMonths($format = '%02d'): array
    {
        $months = [];
        for ($i = 1; $i <= 12; $i++) {
            $val = sprintf($format, $i);
            $label = Date('F', strtotime('2000-' . $val . '-01'));
            $months[$val] = $label;
        }
        return $months;
    }