Scope For DateTime.

@param Illuminate\Database\Query $query
@param Carbon                    $datetime Date and Time of inquiry

@return Illuminate\Database\Query Scoped query
161355
public function scopeForDateTime($query, Carbon $datetime)
    {
        return $query->where('start_at', '<=', $datetime->toDateTimeString())
                        ->where('finish_at', '>=', $datetime->toDateTimeString());
    }
480422
public function getDatetimeObject($datetime = null)
    {
        if ($datetime instanceof DateTimeInterface) {
            return $datetime;
        }

        if (is_integer($datetime)) {
            $datetime = date('Y-m-d H:i:s', $datetime);
        }

        return new DateTime($datetime);
    }
1186261
protected function resolveCacheLifetime($lifetime): DateTime
    {
        if ($lifetime instanceof DateTime) {
            return $lifetime;
        }

        if (is_int($lifetime)) {
            return Carbon::now()->addMinutes($lifetime);
        }
    }
294819
protected function convertDateTimeToDbValue(QueryBuilder $builder, DateTimeInterface $dateTime): string
    {
        $dbDateTimeFormat = $builder->getConnection()->getDatabasePlatform()->getDateTimeFormatString();
        $value            = $dateTime->format($dbDateTimeFormat);

        return $value;
    }
764915
public function scopeByYearMonth($query, $year, $month)
	{
		return $query->where(\DB::raw('DATE_FORMAT(published_date, "%Y%m")'), '=', $year.$month);
	}
487403
private function validateTimezone(DateTime $dateTime)
    {
        $dateTime = Carbon::instance($dateTime);

        // Make sure we have the proper timezone. This is to prevent a developer accidentally removing more than they
        // expect to remove
        if ($dateTime->getTimezone()->getName() !== 'UTC') {
            throw new \InvalidArgumentException('Passed datetime is not in UTC timezone.');
        }

        return $dateTime;
    }
219424
public function getDonationDataSuccess(\DateTime $dateTime)
    {
        $query = $this->createQueryBuilder('p')
            ->select('SUM(p.coins) as coins, COUNT(p.coins) as amount')
            ->where('p.success = :success')
            ->setParameter('success', Entity::STATUS_SUCCESS)
            ->andWhere('p.created >= :created')
            ->setParameter('created', $dateTime)
            ->andWhere('p.type in (:type)')
            ->setParameter(
                'type',
                [
                    Entity::TYPE_PAYMENT_WALL,
                    Entity::TYPE_SUPER_REWARD,
                    Entity::TYPE_XSOLLA,
                    Entity::TYPE_PAY_PAL,
                    Entity::TYPE_PAYSSION,
                    Entity::TYPE_SOFORT,
                ],
                Connection::PARAM_STR_ARRAY
            )
            ->getQuery();

        return $query->getOneOrNullResult();
    }
600541
public function get(DateTime $date, DateTime $reference_date = null )
    {
        if (is_null($reference_date)) {
            $reference_date = new DateTime();
        }
        
        $diff = $reference_date->diff($date);
        return $this->getText($diff, $date);
    }
262686
protected function filterTimestamp(&$query, $attr = 'updated_at')
    {
        if (!is_null($this->{$attr}) && strpos($this->{$attr}, ' - ') !== false ) {
            list($start_date, $end_date) = explode(' - ', $this->{$attr});
            $query->andFilterWhere(['>=', $attr, (int)strtotime($start_date)]);
            $query->andFilterWhere(['<=', $attr, (int)strtotime($end_date) + 24 * 3600]);
        }
    }
291822
public static function convertToDbDate(\DateTime $dateTime) {
		
		$currentTz = $dateTime->getTimezone();
		$dateTime->setTimezone(new \DateTimeZone(BASE_TIMEZONE));
		$ret = $dateTime->format('Y-m-d');
		$dateTime->setTimezone($currentTz);
		return $ret;
		
	}
901890
public function visit($query, $node, string $context)
    {
        if ($node instanceof $this->node) {
            $bindings = [];
            $sql = [];

            $child0 = $node->getChildByIndex(0);

            if ($child0 instanceof Nodes\KeyNode) {
                $context === Nodes\OrNode::class && $query->orWhereNull($this->parseKey($child0->getValue()));
                $context === Nodes\AndNode::class && $query->whereNull($this->parseKey($child0->getValue()));
            }
        }
    }
691370
public static function createDateFromDateTime(DateTime $dateTime, DateTimeZone $dateTimeZone = NULL) {
    $openYLocaleDate = new OpenYLocaleDate();
    $openYLocaleDate->setDateFromDateTime($dateTime, $dateTimeZone);
    return $openYLocaleDate;
  }
207791
public function scopeWithinPeriod(Builder $query, Period $period)
    {
        $startDateTime = $period->getStartDateTime();
        $endDateTime = $period->getEndDateTime();

        if ($startDateTime && ! $endDateTime) {
            $query->where('viewed_at', '>=', $startDateTime);
        } elseif (! $startDateTime && $endDateTime) {
            $query->where('viewed_at', '<=', $endDateTime);
        } elseif ($startDateTime && $endDateTime) {
            $query->whereBetween('viewed_at', [$startDateTime, $endDateTime]);
        }

        return $query;
    }
123713
protected function getDatePositionIn(Carbon $date_time, $time_period)
    {
        // First we need to validate the time period.
        if (!array_key_exists($time_period, self::$time_periods)) {
            throw new \InvalidArgumentException('Time period must be one of the time periods listed in the class constants');
        }

        // Now we will check to see whether the date is positioned at the beginning of the time
        // period provided.
        $start_date = self::forTimePeriod($time_period, $date_time)->start();
        if ($date_time->copy()->eq($start_date)) {
            return self::START;
        }

        // Now we will check to see whether the date is positioned at the end of the time period
        // provided.
        $end_date = self::forTimePeriod($time_period, $date_time)->end();
        if ($date_time->copy()->eq($end_date)) {
            return self::END;
        }
    }
108917
public function expire(Carbon $datetime)
    {
        TypeChecker::isDate($datetime);
        $carbon = new Carbon($datetime);
        $this->setNotificationData('expires_at', $carbon);

        return $this;
    }
814710
public function getForecast($latitude, $longitude, \DateTime $time = null, array $parameters = null)
    {
        $this->requestedUrl = $this->buildRequestURL($latitude, $longitude, $time, $parameters);

        $this->response = json_decode(file_get_contents($this->requestedUrl), true);
        $this->responseHeaders = $this->parseForecastResponseHeaders($http_response_header);

        return $this->response;
    }
146143
public function scopeUseless($query)
    {
        return $query
            ->where(function ($q) {
                $this->scopeExpired($q);
            })
            ->orWhere(function ($q) {
                $this->scopeFull($q);
            });
    }