Convert db time to unix timestamp

@param $value

@return bool|int
513984
private static function fromTimestamp($value)
    {
        $result = false;
        if (empty($value)) {
            return $result;
        }

        $result = new \DateTime($value);

        return $result->getTimestamp();
    }
733751
private static function _parseDateTimeString($value)
    {
        $result = @preg_match('/^\d\d\d\d-\d?\d-\d?\d \d\d:\d\d:\d\d$/', $value);
        if ($result !== 1)
            return null;
        $timestamp = strtotime($value);
        if ($timestamp === false)
            return null;

        return $timestamp;
    }
671014
public function fromDateTime($value)
    {
        $format = $this->getDateFormat();

        $value = $this->asDateTime($value);

        return $value->format($format);
    }
394570
public function filter($value)
    {

        // If it's already a timestamp, return it as is.
        if (preg_match('/^-?\d+$/', $value) === 1) {
            if ($value < 0) {
                throw new \DomainException('Invalid value');
            }
            return $value;
        }

        // Allow SQL specials.
        if ($this->getConfig('allowSqlSpecials') === true) {
            $temp = strtolower($value);
            if ($temp === 'now()' || $temp === 'current_timestamp') {
                return time();
            }
        }

        // Catch invalid strings.
        $time = strtotime($value);
        if ($time === false) {
            throw new \DomainException('Invalid value');
        }

        return $time;

    }
29906
protected function convert($value, int $type)
    {
        switch ($type) {
            case FieldsInterface::TYPE_INT:
                $result = (int)$value;
                break;
            case FieldsInterface::TYPE_FLOAT:
                $result = (float)$value;
                break;
            case FieldsInterface::TYPE_BOOL:
                $result = is_numeric($value) ? (bool)$value : $value === 't';
                break;
            case FieldsInterface::TYPE_DATE:
                $result = strtotime($value);
                break;
            case FieldsInterface::TYPE_UNIXTIME:
                $result = new \DateTime();
                $result->setTimestamp((int)$value);
                break;
            case FieldsInterface::TYPE_STRING:
                $result = $value ?? '';
                break;
            case FieldsInterface::TYPE_ARRAY:
            default:
                $result = $value;
        }

        return $result;
    }
1211506
static public function toUnixtime($value=null)
    {
        return (empty($value)) ? time() : (is_numeric($value) ? $value : strtotime($value));
    }
244661
protected static function _getDateString($value)
    {
        $formatted = '';
        if (isset($value['year'], $value['month'], $value['day']) &&
            (is_numeric($value['year']) && is_numeric($value['month']) && is_numeric($value['day']))
        ) {
            $formatted .= sprintf('%d-%02d-%02d ', $value['year'], $value['month'], $value['day']);
        }

        if (isset($value['hour'])) {
            if (isset($value['meridian']) && (int)$value['hour'] === 12) {
                $value['hour'] = 0;
            }
            if (isset($value['meridian'])) {
                $value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12;
            }
            $value += ['minute' => 0, 'second' => 0];
            if (is_numeric($value['hour']) && is_numeric($value['minute']) && is_numeric($value['second'])) {
                $formatted .= sprintf('%02d:%02d:%02d', $value['hour'], $value['minute'], $value['second']);
            }
        }

        return trim($formatted);
    }
402115
public function isTimezone($value)
    {
        try {
            new DateTimeZone($value);
        } catch (Exception $e) {
            return false;
        } catch (Throwable $e) {
            return false;
        }

        return true;
    }
1101272
public function convertToPHPValue($value, AbstractPlatform $platform) : ?DateTime
    {
        if ($value === null || $value instanceof DateTime) {

            return $value;
        }

        if ( ! $this->getUtc() instanceof DateTimeZone) {

            $this->setUtc(new DateTimeZone('UTC'));
        }

        /** @var DateTime $converted */
        $converted = DateTime::createFromFormat(
            $platform->getDateTimeFormatString(),
            $value,
            $this->getUtc()
        );

        if ( ! $converted) {
            throw ConversionException::conversionFailedFormat(
                $value,
                $this->getName(),
                $platform->getDateTimeFormatString()
            );
        }

        return $converted;
    }
1009062
public static function convertToEdmDateTime($value)
    {
        if (empty($value)) {
            return $value;
        }

        if (is_string($value)) {
            $value = self::convertToDateTime($value);
        }

        Validate::isDate($value, 'value');

        $cloned = clone $value;
        $cloned->setTimezone(new \DateTimeZone('UTC'));

        return str_replace('+0000', 'Z', $cloned->format(\DateTime::ISO8601));
    }
901516
public function formatTimeago($value)
    {
        if ($value instanceof DateTime) {
            $value = date_timestamp_get($value);

        } else if (!is_numeric($value) && is_string($value)) {
            $value = strtotime($value);
        }

        return $this->inWords((time() - $value));
    }
474330
protected function convert_string( $value ) {

		$format = $this->input_data[ 'format' ];
		$date   = \DateTime::createFromFormat( $format, $value );

		// Invalid dates can show up as warnings (ie. "2007-02-99") and still return a DateTime object.
		$errors = \DateTime::getLastErrors();
		if ( $errors[ 'warning_count' ] > 0 ) {
			$this->error_code = Error\ErrorLoggerInterface::INVALID_DATE_FORMAT;

			return FALSE;
		}

		return $date;
	}
1305171
private function timestampFromBigQuery($value)
    {
        // If the string contains 'E' convert from exponential notation to
        // decimal notation. This doesn't cast to a float because precision can
        // be lost.
        if (strpos($value, 'E')) {
            list($value, $exponent) = explode('E', $value);
            list($firstDigit, $remainingDigits) = explode('.', $value);

            if (strlen($remainingDigits) > $exponent) {
                $value = $firstDigit . substr_replace($remainingDigits, '.', $exponent, 0);
            } else {
                $value = $firstDigit . str_pad($remainingDigits, $exponent, '0') . '.0';
            }
        }

        $parts = explode('.', $value);
        $unixTimestamp = $parts[0];
        $microSeconds = isset($parts[1])
            ? $parts[1]
            : 0;

        $dateTime = new \DateTime("@$unixTimestamp");

        // If the timestamp is before the epoch, make sure we account for that
        // before concatenating the microseconds.
        if ($microSeconds > 0 && $unixTimestamp[0] === '-') {
            $microSeconds = 1000000 - (int) str_pad($microSeconds, 6, '0');
            $dateTime->modify('-1 second');
        }

        return new Timestamp(
            new \DateTime(
                sprintf(
                    '%s.%s+00:00',
                    $dateTime->format('Y-m-d H:i:s'),
                    $microSeconds
                )
            )
        );
    }
273526
static public function create_time($value=null)
    {
        return (empty($value)) ? time() : (is_numeric($value) ? $value : strtotime($value));
    }
760058
public function convertToDatabaseValue($value, AbstractPlatform $platform)
     {
         if ($value === null) {
             return;
         }
         $formatString = $platform->getDateTimeFormatString();

         $formatted = $value->setTimezone(new \DateTimeZone('UTC'))->format($formatString);

         return $formatted;
     }
1131035
protected function databaseValue($value)
    {
        if (!$value instanceof \DateTime) {
            throw ODMException::conversionFailedInvalidType($value, Type::DATE, ['null', 'DateTime']);
        }

        $this->setToMidnight($value);

        return (string)$value->getTimestamp();
    }
629290
public static function canCastToDateTime($value)
    {
        if ($value instanceof \DateTime) {
            return true;
        } elseif (is_numeric($value)) {
            $value = (float)$value;
            return $value >= 0;
        } elseif (is_string($value)) {
            return $value !== '';
        } elseif (is_object($value)) {
            return method_exists($value, '__toString') && ((string)$value) !== '';
        }
        return false;
    }