@param \DateTime $datetime

@return int
340368
public static function getWeekNumberOfMonth($datetime)
    {
        $first_day_of_month = clone $datetime;
        $first_day_of_month->modify('first day of this month');

        return ceil($datetime->format('W') - $first_day_of_month->format('W')) + 1;
    }
53936
public static function fromDateTime(DateTime $dateTime)
    {
        $date = new Date();
        $date->setYear(intval($dateTime->format('Y')));
        $date->setMonth(intval($dateTime->format('m')));
        $date->setDay(intval($dateTime->format('d')));

        $result = new AdManagerDateTime();
        $result->setDate($date);
        $result->setHour(intval($dateTime->format('H')));
        $result->setMinute(intval($dateTime->format('i')));
        $result->setSecond(intval($dateTime->format('s')));
        $result->setTimeZoneID($dateTime->format('e'));

        return $result;
    }
63349
private function validateDateTime($datetime)
    {
        if (preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', $datetime, $parts) == true) {
            $time = gmmktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);

            $input_dt = new \DateTime($datetime, new \DateTimeZone('GMT0'));
            $input_time = $input_dt->getTimestamp();
            if ($input_time === false) return false;

            return $input_time == $time;
        } else {
            return false;
        }
    }
1271846
public static function lowest(... $datetimes)
    {
        $lowest = null;
        foreach ($datetimes as $datetime) {
            if (!$datetime instanceof \DateTimeInterface) {
                continue;
            }

            if ($datetime < $lowest || null === $lowest) {
                $lowest = $datetime;
            }
        }

        return $lowest;
    }
200161
public function findEndBefore(\DateTime $dateTime)
    {
        return $this->createQueryBuilder('t')
            ->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime')
            ->setParameter('dateTime', $dateTime)
            ->getQuery()
            ->getResult();
    }
234086
public static function isValidDateTime($dateTime)
    {
        $t = explode(' ', $dateTime);
        if ($this->isValidDate($t[0]) && $this->isValidDate($t[1])) {
            return true;
        } else {
            return false;
        }
    }
691370
public static function createDateFromDateTime(DateTime $dateTime, DateTimeZone $dateTimeZone = NULL) {
    $openYLocaleDate = new OpenYLocaleDate();
    $openYLocaleDate->setDateFromDateTime($dateTime, $dateTimeZone);
    return $openYLocaleDate;
  }
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;
    }
197107
public static function getTimestamp($dateTime = null)
    {
        return $dateTime ? is_numeric($dateTime) ? $dateTime : strtotime($dateTime) : time();
    }
873357
public function compareTo(LocalDateTime $that) : int
    {
        return $this->date->compareTo($that->date) ?: $this->time->compareTo($that->time);
    }
141872
public static function toHttpDate(\DateTime $dateTime)
        {
            // We need to clone it, as we don't want to affect the existing
            // DateTime.
            $dateTime = clone $dateTime;
            $dateTime->setTimeZone(new \DateTimeZone('GMT'));
            return $dateTime->format('D, d M Y H:i:s \G\M\T');
        }
484014
public function getDate(\DateTimeInterface $dateTime)
    {
        $date = new Date($dateTime);
        $this->loadDay($date);

        return $date;
    }
708980
public function differenceDateTime($dateTime = null) {
        if (!empty($dateTime)) {
            $this->setDateTime($dateTime, true);
        }
        $this->dateTimeInterval = $interval = $this->dateTime->diff($this->dateTimeDiff);
        return $interval;
    }
553892
public function format(\DateTime $dateTime)
    {
        $formatted = preg_replace_callback($this->regExp, function ($matches) use ($dateTime) {
            return $this->formatReplace($matches[0], $dateTime);
        }, $this->pattern);

        return $formatted;
    }
1085746
protected function isLeapYear(\DateTime $date)
    {
        $year = (int) $date->format('Y');
        return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0)));
    }
298787
public static function getDateTime($datetime = null)
    {
        if ($datetime instanceof \DateTime) {
            return clone $datetime;
        }
        if ($datetime instanceof \DateTimeImmutable) {
            return new \DateTime($datetime->format(\DateTime::ATOM));
        }
        if (\is_string($datetime)) {
            if (\is_numeric($datetime)) {
                /*
                    check if datetime is an int of the the form YYYYMMDD or YYYYMMDDHHMMSS
                    Debug::_log('datetime', $datetime)
                */
                $isTs = !preg_match('/^(19|20)\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\d|2[0-3])\d[0-5]\d[0-5]\d)?$/', $datetime);
                if ($isTs) {
                    $datetime = '@'.$datetime;
                }
            }
            Debug::_log('datetime', $datetime);
            return new \DateTime($datetime);
        }
        if (\is_int($datetime) || \is_float($datetime)) {
            $dateTime = new \DateTime();
            $dateTime->setTimestamp($datetime);
            return $dateTime;
        }
        return new \DateTime();
    }
550432
public function computeNumTimesFiredBetween(\DateTime $start, \DateTime $end)
    {
        if ($this->getRepeatInterval() < 1) {
            return 0;
        }

        $time = ((int) $end->format('U')) - ((int) $start->format('U'));

        return (int) ($time / $this->getRepeatInterval());
    }