Schedule the event to run between start and end time.

@param  string  $startTime
@param  string  $endTime
@return \Closure
435044
private function inTimeInterval($startTime, $endTime)
    {
        return function () use ($startTime, $endTime) {
            return Carbon::now($this->timezone)->between(
                Carbon::parse($startTime, $this->timezone),
                Carbon::parse($endTime, $this->timezone),
                true
            );
        };
    }
966747
public function process(DateTime $startDate, DateTime $endDate, DateTime $cycleDate)
    {
        $this->logger->info('Control Mirakl Settings', array('miraklId' => null, "action" => "Operations creation"));
        // control mirakl settings
        $boolControl = $this->getControlMiraklSettings($this->documentTypes);
        if ($boolControl === false) {
            // log critical
            $title = $this->criticalMessageMiraklSettings;
            $message = $this->formatNotification->formatMessage($title);
            $this->logger->critical($message, array('miraklId' => null, "action" => "Operations creation"));
        } else {
            $this->logger->info(
                'Control Mirakl Settings OK',
                array('miraklId' => null, "action" => "Operations creation")
            );
        }

        $this->logger->info('Cashout Initializer', array('miraklId' => null, "action" => "Operations creation"));

        //Fetch Invoices
        $this->logger->info(
            'Fetch invoices documents from Mirakl from ' .
            $startDate->format('Y-m-d H:i') .
            ' to ' .
            $endDate->format('Y-m-d H:i')
            ,
            array('miraklId' => null, "action" => "Operations creation")
        );

        // get invoices from Mirakl API
        $invoices = $this->getInvoices($startDate, $endDate);

        $this->logger->info(
            '[OK] Fetched ' . count($invoices) . ' invoices',
            array('miraklId' => null, "action" => "Operations creation")
        );

        $this->logger->info('Process invoices', array('miraklId' => null, "action" => "Operations creation"));

        $operations = $this->processInvoices($invoices, $cycleDate);

        $this->saveOperations($operations);

    }
894252
public function during($startDate, $endDate)
    {
        $validationResult = QueryValidator::validateCustomDateRange(
            $startDate,
            $endDate
        );
        if ($validationResult->isFailed()) {
            throw new InvalidArgumentException('The start or end date is' .
                ' invalid. Validation fail reasons: ' .
                $validationResult->getFailReason());
        }

        $this->duringStartDate = $startDate;
        $this->duringEndDate = $endDate;
    }
1006198
public function endTimer($timer, $endTime = null)
	{
		$this->timers[$timer]->end($endTime);

		return $this;
	}
1267950
public function getAllEvents($starttime = null, $endtime = null) {

		if (is_null($starttime)) {
			$starttime = time();
		}
		if (is_null($endtime)) {
			$endtime = strtotime('+1 year', $starttime);
		}

		$starttime = sanitize_int($starttime);
		$endtime = sanitize_int($endtime);
		$relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP);

		$dbprefix = elgg_get_config('dbprefix');

		$mds_name = elgg_get_metastring_id('start_timestamp');
		$mdre_name = elgg_get_metastring_id('repeat_end_timestamp');

		$options = array(
			'type' => 'object',
			'subtype' => Event::SUBTYPE,
			'joins' => array(
				"JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship
				"JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata
				"JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring
				"JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid", // repeat end time metadata
				"JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" // repeat end time metastring
			),
			'wheres' => array(
				"er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'",
				"mds.name_id = {$mds_name}",
				"mdre.name_id = {$mdre_name}",
				// event start is before our endtime AND (repeat end is after starttime, or there is no repeat end)
				"((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))"
			),
			'limit' => false
		);

		return new ElggBatch('elgg_get_entities', $options);
	}
1080409
public function setStartTimeOfDay(\DateTime $startTimeOfDay)
    {
        $startTimeOfDay = clone $startTimeOfDay;
        $startTimeOfDay->setDate(1970, 1, 1); // zero date

        if ($this->getEndTimeOfDay() && $this->getEndTimeOfDay() < $startTimeOfDay) {
            throw new \InvalidArgumentException('End time of day cannot be before start time of day');
        }

        $this->setValue('startTimeOfDay', $startTimeOfDay);
    }
398213
public function run(Datetime $runTime = null)
    {
        $jobs = $this->getQueuedJobs();

        if (is_null($runTime)) {
            $runTime = new DateTime('now');
        }

        foreach ($jobs as $job) {
            if ($job->isDue($runTime)) {
                try {
                    $job->run();
                    $this->pushExecutedJob($job);
                } catch (\Exception $e) {
                    $this->pushFailedJob($job, $e);
                }
            }
        }

        return $this->getExecutedJobs();
    }
915634
public function getEventsQuery(\DateTime $begin, \DateTime $end, array $options = array())
    {
        return $this->getEventsQueryBuilder($begin, $end, $options)->getQuery();
    }
1149904
protected function getInterval($fromTime, $toTime = null)
    {
        $fromTime = new DateTime($this->normalizeDate($fromTime));
        $toTime   = new DateTime($this->normalizeDate($toTime));

        return $fromTime->diff($toTime);
    }
236719
public function between(DateTime $start, DateTime $end) {
        $this->start($start)
                ->end($end);

        return $this;
    }
1282774
public function getEvents(\DateTime $begin, \DateTime $end, array $options = array())
    {
        $events = array();

        foreach ($this->providers as $provider) {
            $events = array_merge($events, $provider->getEvents($begin, $end, $options));
        }

        return $events;
    }
844381
private function createTimestampCalendar(
        DateTimeInterface $startDate,
        DateTimeInterface $endDate,
        CultureFeed_Cdb_Data_Calendar_TimestampList $calendar,
        $index = null
    ) {
        // Make a clone of the original calendar to avoid updating input param.
        $newCalendar = clone $calendar;

        $first24Hours = Period::createFromDuration($startDate, new DateInterval('P1D'));

        // Easy case an no seconds needed for indexing.
        if ($first24Hours->contains($endDate)) {
            $newCalendar->add(
                new CultureFeed_Cdb_Data_Calendar_Timestamp(
                    $startDate->format('Y-m-d'),
                    $this->formatDateTimeAsCdbTime($startDate),
                    $this->formatDateTimeAsCdbTime($endDate)
                )
            );
        } elseif (is_int($index)) {
            // Complex case and seconds needed for indexing.
            $period = new Period($startDate, $endDate);

            $startTimestamp = new CultureFeed_Cdb_Data_Calendar_Timestamp(
                $startDate->format('Y-m-d'),
                $this->formatDateTimeAsCdbTime($startDate, $index)
            );

            $endTimestamp = new CultureFeed_Cdb_Data_Calendar_Timestamp(
                $endDate->format('Y-m-d'),
                $this->createIndexedTimeString($index),
                $this->formatDateTimeAsCdbTime($endDate)
            );

            $untilEndOfSecondDay = new Period(
                $startDate,
                Chronos::instance($startDate)->addDay()->endOfDay()
            );

            if ($untilEndOfSecondDay->contains($endDate)) {
                $fillerTimestamps = [];
            } else {
                $days = iterator_to_array($period->getDatePeriod('1 DAY'));
                $fillerTimestamps = array_map(
                    function (DateTimeInterface $dateTime) use ($index) {
                        return new CultureFeed_Cdb_Data_Calendar_Timestamp(
                            $dateTime->format('Y-m-d'),
                            $this->createIndexedTimeString($index)
                        );
                    },
                    array_slice($days, 1, count($days) === 2 ? 2 : -1)
                );
            }

            $newCalendar = array_reduce(
                array_merge([$startTimestamp], $fillerTimestamps, [$endTimestamp]),
                function (CultureFeed_Cdb_Data_Calendar_TimestampList $calendar, $timestamp) {
                    $calendar->add($timestamp);
                    return $calendar;
                },
                $newCalendar
            );
        }

        return $newCalendar;
    }
1236974
public void setInterval(ReadableInstant start, ReadableInstant end) {
        if (start == null && end == null) {
            long now = DateTimeUtils.currentTimeMillis();
            setInterval(now, now);
        } else {
            long startMillis = DateTimeUtils.getInstantMillis(start);
            long endMillis = DateTimeUtils.getInstantMillis(end);
            Chronology chrono = DateTimeUtils.getInstantChronology(start);
            super.setInterval(startMillis, endMillis, chrono);
        }
    }
200161
public function findEndBefore(\DateTime $dateTime)
    {
        return $this->createQueryBuilder('t')
            ->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime')
            ->setParameter('dateTime', $dateTime)
            ->getQuery()
            ->getResult();
    }
1371014
public static function createFromDuration($duration, DateTime $end = null) : self
    {
        if ($duration instanceof DateTime && $end) {
            $duration = $end->getTimestamp() - $duration->getTimestamp();
        }

        return static::create(null, null, null, 0, 0, 0)
            ->addSeconds($duration);
    }
1058484
public function setTime(DateTime $time = null)
    {
        $timestamp = $time ? $time->getTimestamp() : null;

        $this->session->put($this->timePersistenceKey, $timestamp);

        if ($time) {
            $this->setState(static::HISTORY);
        }

        return $this;
    }
1079445
protected function setStarted($time = null)
    {
        $this->started = $time ?: microtime(true);
        $this->setState(RunInterface::STATE_RUNNING);
    }