Method converts \MongoDB\BSON\UTCDateTime to \DateTime.

@param VisitorInterface $visitor
@param UTCDatetime      $date
@param array            $type
@param Context          $context

@return \DateTime
975730
public function convertFromMongoFormatToDateTime(VisitorInterface $visitor, $date, array $type, Context $context)
    {
        /**
         * this $dateTime object is incorrect in case of using microseconds
         * because after conversion of \MongoDB\BSON\UTCDateTime to \DateTime
         * method $dateTime->format('U.u') returns invalid string xxxxxxxxx.zzzzzzzzz
         * part after "." contains 9 digits but it should contain up to 6 digits
         * so we have to reduce this part to 6 digits.
         *
         * @var \DateTime
         */
        if (!is_string($date) && !$date instanceof UTCDatetime) {
            throw new \InvalidArgumentException('The provided date must be a valid string or an instance of UTCDateTime');
        }

        if (is_string($date)) {
            $dateTime = date_create($date);
            if (false === $dateTime) {
                throw new \InvalidArgumentException(sprintf('The provided date "%s" is not a valid date/time string', $date));
            }

            return $dateTime;
        }

        return self::convertMongoFormatToDateTime($date);
    }
69696
public function normalize($object, $format = null, array $context = array())
    {
        if (!$object instanceof \DateTimeInterface) {
            throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
        }

        $format = isset($context[static::CONTEXT_FORMAT]) ? $context[self::CONTEXT_FORMAT] : $this->format;

        return $object->format($format);
    }
876196
public function doSerialize(
        JsonSerializationVisitor $visitor,
        Structure $structure,
        array $type,
        Context $context
    ) {
        $array = $structure->toArray();

        return $context->accept($array);
    }
782732
public function serialize(VisitorInterface $visitor, ?UuidInterface $uuid, Type $type, Context $context): ?string
    {
        if (null === $uuid) {
            return $visitor->visitNull(null, Type::null(), $context);
        }

        return $visitor->visitString($uuid->toString(), $type, $context);
    }
1285164
public static function formatFromConfig($type, $date) {
        $ini = Zend_Registry::get('config');
        $format = $ini->date->format->$type;

        if (strpos($format, '%') !== false) {
            return strftime($format, strtotime($date));
        } else {
            return date($format, strtotime($date));
        }
    }
1174025
protected static function expectDateTime($date)
    {
        if (!$date instanceof DateTime && !$date instanceof DateTimeInterface) {
            throw new InvalidArgumentException(
                'Expected null, string, DateTime or DateTimeInterface, '.
                (is_object($date) ? get_class($date) : gettype($date)).' given'
            );
        }
    }
262354
public static function date($sec = null, $usec = 0)
    {
        $sec === null && $sec = time();

        return new MongoDate($sec, $usec);
    }
3776
private function deserialize($data, TypeMetadataInterface $type, ContextInterface $context)
    {
        $class = $type->getName();

        if (!method_exists($class, 'createFromFormat')) {
            throw new \InvalidArgumentException(sprintf(
                'The method "%s" does not exist on "%s".',
                'createFromFormat',
                $class
            ));
        }

        if (!method_exists($class, 'getLastErrors')) {
            throw new \InvalidArgumentException(sprintf(
                'The method "%s" does not exist on "%s".',
                'getLastErrors',
                $class
            ));
        }

        $result = $class::createFromFormat(
            $format = $type->getOption('format', $this->format),
            (string) $data,
            $timezone = new \DateTimeZone($type->getOption('timezone', $this->timeZone))
        );

        $errors = $class::getLastErrors();

        if (!empty($errors['warnings']) || !empty($errors['errors'])) {
            throw new \InvalidArgumentException(sprintf(
                'The date "%s" with format "%s" and timezone "%s" is not valid.',
                $data,
                $format,
                $timezone->getName()
            ));
        }

        return $result;
    }
69497
public static function compare($date1, $date2, $type = 'date') {
		if ($type == 'date') {
			return date('Y-m-d', strtotime($date1)) === date('Y-m-d', strtotime($date2));
		} else if ($type == 'datetime' || $type == 'time') {
			return date('Y-m-d H:i:s', strtotime($date1)) === date('Y-m-d H:i:s', strtotime($date2));
		} else {
			return strtotime($date1) == strtotime($date2);
		}
	}
1195822
public static function get(UTCDateTime $date): DateTime
    {
        $date = $date->toDateTime();
        $date->setTimezone(new DateTimeZone(date_default_timezone_get()));

        return $date;
    }
221944
private function dateTimeToTimePoint(DateTime $date)
    {
        // missing or offset only timezone? correct to UTC
        if (!$date->getTimezone() instanceof DateTimeZone || preg_match('#^[+-]{1}[0-9]{2}:?[0-9]{2}$#', $date->getTimezone()->getName())) {
            $date->setTimezone(new DateTimeZone('UTC'));
        }

        try {
            // DateTime::createFromFormat() will create an invalid DateTimeZone object when the timezone is an offset
            // (-05:00, for example) instead of a named timezone. By recreating the DateTimeZone object, we can expose
            // this problem and ensure that a valid DateTimeZone object is always set.
            $timezone = new DateTimeZone($date->getTimezone()->getName());
        } catch (Exception $e) {
            // @codeCoverageIgnoreStart
            $date->setTimezone(new DateTimeZone('UTC'));
            // @codeCoverageIgnoreEnd
        }

        return new TimePoint(
            (int) $date->format('Y'),
            (int) $date->format('m'),
            (int) $date->format('d'),
            (int) $date->format('H'),
            (int) $date->format('i'),
            (int) $date->format('s'),
            $date->getTimezone()->getName(),
            (int) $date->format('u')
        );
    }
470690
public function deserializeArrayObjectFromJson(
        JsonDeserializationVisitor $visitor,
        array $data,
        array $type,
        Context $context
    ) {
        return new \ArrayObject($visitor->visitArray($data, $type, $context));
    }
386378
public function deserializeHashFromJson(
        JsonDeserializationVisitor $visitor,
        array $data,
        array $type,
        Context $context
    ) {
        $currentPath = $context->getCurrentPath();
        $currentRequestContent = $this->getCurrentRequestContent();
        $dataObj = null;

        if (!is_null($currentRequestContent)) {
            $dataObj = $currentRequestContent;
            foreach ($currentPath as $pathElement) {
                if (isset($dataObj->{$pathElement})) {
                    $dataObj = $dataObj->{$pathElement};
                } else {
                    $dataObj = null;
                    break;
                }
            }
        }

        if (!is_null($dataObj)) {
            if ($this->isSequentialArrayCase($dataObj, $data)) {
                $dataObj = $dataObj[$this->getLocationCounter($currentPath)];
            }

            $data = $dataObj;
        }

        return new Hash($visitor->visitArray((array) $data, $type, $context));
    }
1299250
private function legacyGetMongoDbDateTime(\DateTimeInterface $value): UTCDateTime
    {
        $milliseconds = floor($value->format('U.u') * 1000);

        $milliseconds = (PHP_INT_SIZE == 8) //64-bit OS?
            ? (int) $milliseconds
            : (string) $milliseconds;

        return new UTCDateTime($milliseconds);
    }
423096
public function serializeToXml(XmlSerializationVisitor $visitor, $entity, array $type, Context $context)
    {
        $visitor->getCurrentNode()->appendChild(
            $formNode = $visitor->getDocument()->createElement('id', $type['params']['id'])
        );

        return $formNode;
    }
687242
public static function refreshTokensExpireIn(DateTimeInterface $date = null)
    {
        if (is_null($date)) {
            return static::$refreshTokensExpireAt
                            ? Carbon::now()->diff(static::$refreshTokensExpireAt)
                            : new DateInterval('P1Y');
        }

        static::$refreshTokensExpireAt = $date;

        return new static;
    }
1300066
public function setDate(\DateTimeInterface $date): self
    {
        if ($date instanceof \DateTime) {
            $date = \DateTimeImmutable::createFromMutable($date);
        }
        $date = $date->setTimezone(new \DateTimeZone('UTC'));
        $this->headers->set('Date', $date->format('D, d M Y H:i:s') . ' GMT');

        return $this;
    }