Returns exports that crashed. If a date is provided, only exports created
before this date are returned.

@param \DateTime $before An optional date to search

@return array
426719
public function findCrashedExports(\DateTime $before = null)
    {
        $qb = $this->createQueryBuilder('e');
        $qb->where($qb->expr()->gte('e.crash', 'e.nbretry'));

        if (null !== $before) {
            $qb->andWhere($qb->expr()->lte('e.created', ':created'));
            $qb->setParameter(':created', $before);
        }

        return $qb->getQuery()->getResult();
    }
465310
public function getChangedProperties(\DateTime $date)
    {
        $properties = array();

        $xml = $this->execute(sprintf('property/%s', $date->format('Y/m/d/H/i/s')));

        foreach ($xml->property as $xmlProperty) {
            $property = new ChangedPropertySummary;
            $property->setPropId(self::normalise($xmlProperty->propid, 'int'));
            $property->setLastChanged(self::normalise($xmlProperty->lastchanged, 'datetime'));
            $property->setLastAction(self::normalise($xmlProperty->action, 'string'));
            $property->setUrl(self::normalise($xmlProperty->url, 'string'));
            $properties[] = $property;
        }

        return $properties;
    }
959176
public static function today($timeZone = null)
    {
        $now = null;
        $before = null;
        if ( is_null($timeZone) ) {
            $now = new \DateTime();
            $before = new \DateTime();
        } else {
            $now = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
            $before = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
        }
        $range = new Range( $before, $now );

        return $range;
    }
641599
public function getWorkoutsFromTo(\DateTime $from, \DateTime $to)
    {
        return $this->getWorkouts([
            'after' => $from->format('c'),
            'before' => $to->format('c'),
        ]);
    }
468126
private function prepareDateTimes($datetimes)
    {
        $parsedDateTimes = $this->parseDateTimes($datetimes);
        $sortedDateTimes = array();
        foreach ($parsedDateTimes as $parsedDateTime) {
            $hour = date('G', $parsedDateTime->date_time->getTimestamp());
            if (!isset($sortedDateTimes[$hour])) {
                $sortedDateTimes[$hour] = array();
            }
            if ($this->hasExceptions($parsedDateTime->links)) {
                usort($parsedDateTime->links, array($this, "sortLinks"));
            }
            $sortedDateTimes[$hour][] = $parsedDateTime;
        }

        return $sortedDateTimes;
    }
886822
public function get(string $date = null) : array
    {
        if ($date === null) {
            $date = \date('Y-m-d');
        }

        return [
            'queued' => $this->queue->count(),
            'pass' => $this->queue->getStatsByType($date, 'pass'),
            'fail' => $this->queue->getStatsByType($date, 'fail'),
            'retry' => $this->queue->getStatsByType($date, 'retry'),
            'cancel' => $this->queue->getStatsByType($date, 'cancel')
        ];
    }
522929
public function getLastFeedExportDate()
    {
        $file = new SplFileInfo($this->config->getDefaultFeedFile());
        if (!$file->isFile()) {
            return null;
        }

        return new DateTime('@' . $file->getMTime());
    }
1120273
public function getDateString(DateTime $time)
	{
		if ($this->getOption('type') === 'date')
		{
			return $time->format('Y-m-d');
		}
		else if ($this->getOption('type') === 'datetime')
		{
			return $time->format('Y-m-d H:i:s');
		}
		else
		{
			return $time->format('H:i:s');
		}
	}
690125
public function all($includingRead = false, $participating = false, DateTime $since = null, DateTime $before = null)
    {
        $parameters = [
            'all' => $includingRead,
            'participating' => $participating,
        ];

        if ($since !== null) {
            $parameters['since'] = $since->format(DateTime::ISO8601);
        }

        if ($before !== null) {
            $parameters['before'] = $before->format(DateTime::ISO8601);
        }

        return $this->get('/notifications', $parameters);
    }
898806
public function getProductsInModifiedInterval(int $siteId, \DateTimeInterface $dateStart, \DateTimeInterface $dateEnd) : array
    {
        Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive');
        Assert::that($dateStart)->lessThan($dateEnd, '$dateStart has to be before $dateEnd');

        return (array)$this->master->doRequest(
            'GET',
            sprintf(
                '/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/GetByModifiedInterval/%d?start=%s&end=%s',
                $siteId,
                $dateStart->format('Y-m-d\TH:i:s'),
                $dateEnd->format('Y-m-d\TH:i:s')
            )
        );
    }
688262
public function getChangedFiles(\DateTime $date)
    {
        $files = array();

        $xml = $this->execute(sprintf('files/%s', $date->format('Y/m/d/H/i/s')));

        foreach ($xml->file as $xmlFile) {
            $file = new ChangedFileSummary;
            $file->setFileId(self::normalise($xmlFile->{'file_id'}, 'int'));
            $file->setFilePropId(self::normalise($xmlFile->{'file_propid'}, 'int'));
            $file->setLastChanged(self::normalise($xmlFile->updated, 'datetime'));
            $file->setIsDeleted(self::normalise($xmlFile->deleted, 'bool'));
            $file->setUrl(self::normalise($xmlFile->url, 'string'));
            $file->setPropUrl(self::normalise($xmlFile->{'prop_url'}, 'string'));
            $files[] = $file;
        }

        return $files;
    }
183781
public function dateIsInRange(\DateTime $date) {
    $dateInRange = FALSE;

    $t1 = $this->start_date->getTimeStamp();
    $t2 = $this->end_date->getTimeStamp();

    $t3 = $date->getTimeStamp();

    if (($t3 >= $t1) && ($t3 <= $t2)) {
      $dateInRange = TRUE;
    }

    return $dateInRange;
  }
533883
public static function getRelTime($datetime, $datetimeFrom = null)
    {
        $ret = '';
        $dateTime = self::getDateTime($datetime);
        $dateTimeFrom = self::getDateTime($datetimeFrom);
        $dateTimeSameDay = clone $dateTimeFrom;
        $dateTimeSameDay->setTime(0, 0, 0);
        $diffSec = $dateTimeFrom->getTimestamp() - $dateTime->getTimestamp();
        if ($dateTime > $dateTimeFrom) {
            // Future
            $dateTimeTest = clone $dateTimeSameDay;
            if ($dateTime < $dateTimeTest->modify('tomorrow')) {
                $ret = 'Today at '.$dateTime->format('g:ia');
            } elseif ($dateTime < $dateTimeTest->modify('+2 days')) {
                $ret = 'Tomorrow at '.$dateTime->format('g:ia');
            } else {
                $ret = $dateTime->format('F jS');
            }
        } elseif ($diffSec < 60) {
            // within a min
            $ret = 'Just now';
        } elseif ($diffSec < 3600) {
            // within an hour
            $ret = \round(($diffSec)/60) .' min ago';
        } elseif ($diffSec < 3600*6) {
            // within 6 hours
            $hrs = \round(($diffSec)/3600);
            $ret = $hrs.' '.Str::plural($hrs, 'hour').' ago';
        } elseif ($dateTime > $dateTimeSameDay) {             // since midnight so it's today
            $ret = 'Today at '.$dateTime->format('g:ia');
        } elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400) {
            $ret = 'Yesterday at '.$dateTime->format('g:ia');
        } elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400*7) {
            $ret = $dateTime->format('l \a\t g:ia');
        } elseif ($dateTime->getTimestamp() > \mktime(0, 0, 0, 1, 1)) {// since 1st Jan so it's this year
            $ret = $dateTime->format('F jS');
        } else {                                // last year..
            $ret = $dateTime->format('F jS, Y');
        }
        $ret = \str_replace(' at 12:00am', '', $ret);
        return $ret;
    }
571029
function getFirstLastDate($dateA, $dFormat = "Y/m/d") {

//    $fDate = $lDate = date("m/d/y",time());
        $fDate = $lDate = date($dFormat, time());
        asort($dateA); // TODO
        $i = 0;
        $maxItem = count($dateA);
        foreach ($dateA as $k => $one) {
            if ($i == 0)
                $firstDate = $k;
            if ($i == $maxItem - 1)
                $lastDate = $k;
            $i++;
        }
        $fDate = date($dFormat, strtotime($firstDate));
        $lDate = date($dFormat, strtotime($lastDate));
        return array($fDate, $lDate);
    }
247102
private function getClosestDateAfter(\DateTime $date)
    {
        $tmpDate = clone $date;
        $dayOfWeek = (int) $tmpDate->format('N');
        $time = Time::fromDate($tmpDate);

        if (!$this->holidays->isHoliday($tmpDate) && null !== $day = $this->getDay($dayOfWeek)) {
            if (null !== $closestTime = $day->getClosestOpeningTimeAfter($time, $tmpDate)) {
                $tmpDate->setTime($closestTime->getHours(), $closestTime->getMinutes(), $closestTime->getSeconds());

                return $tmpDate;
            }
        }

        $tmpDate = $this->getDateAfter($tmpDate);

        while ($this->holidays->isHoliday($tmpDate)) {
            $tmpDate = $this->getDateAfter($tmpDate);
        }

        $closestDay = $this->getClosestDayBefore((int) $tmpDate->format('N'));
        $closingTime = $closestDay->getOpeningTime($tmpDate);
        $tmpDate->setTime($closingTime->getHours(), $closingTime->getMinutes(), $closingTime->getSeconds());

        return $tmpDate;
    }
427166
public function getNextInvalidTimeAfter(\DateTime $date)
    {
        $difference = 1;

        $lastDate = clone $date;

        // IMPROVE THIS! The following is a BAD solution to this problem. Performance will be very bad here, depending on the cron expression. It is, however A solution.

        //keep getting the next included time until it's farther than one second
        // apart. At that point, lastDate is the last valid fire time. We return
        // the second immediately following it.
        while ($difference == 1) {
            try {
                $newDate = $this->getCronExp()->getNextRunDate($lastDate);
            } catch (\RuntimeException $e) {
                break;
            }

            $difference = ((int) $newDate->format('U')) - ((int) $lastDate->format('U'));

            if ($difference == 1) {
                $lastDate = $newDate;
            }
        }

        $lastDate->add(new \DateInterval('PT1S'));

        return $lastDate;
    }
654199
public function buildDateTimeRawValue(\DateTime $dateTime = null) {
		if (null === $dateTime) return null;
		return DateUtils::formatDateTime($dateTime, SqliteDateTimeColumn::FORMAT_DATE_TIME);
	}