src/Schema.php
protected function validateDatetime($value, ValidationField $field) {
        if ($value instanceof \DateTimeInterface) {
            // do nothing, we're good
        } elseif (is_string($value) && $value !== '' && !is_numeric($value)) {
            try {
                $dt = new \DateTimeImmutable($value);
                if ($dt) {
                    $value = $dt;
                } else {
                    $value = null;
                }
            } catch (\Throwable $ex) {
                $value = Invalid::value();
            }
        } elseif (is_int($value) && $value > 0) {
            try {
                $value = new \DateTimeImmutable('@'.(string)round($value));
            } catch (\Throwable $ex) {
                $value = Invalid::value();
            }
        } else {
            $value = Invalid::value();
        }

        if (Invalid::isInvalid($value)) {
            $field->addTypeError($value, 'date/time');
        }
        return $value;
    }
protected function validateDatetime($value, ValidationField $field) {
        if ($value instanceof \DateTimeInterface) {
            // do nothing, we're good
        } elseif (is_string($value) && $value !== '' && !is_numeric($value)) {
            try {
                $dt = new \DateTimeImmutable($value);
                if ($dt) {
                    $value = $dt;
                } else {
                    $value = null;
                }
            } catch (\Throwable $ex) {
                $value = Invalid::value();
            }
        } elseif (is_int($value) && $value > 0) {
            try {
                $value = new \DateTimeImmutable('@'.(string)round($value));
            } catch (\Throwable $ex) {
                $value = Invalid::value();
            }
        } else {
            $value = Invalid::value();
        }

        if (Invalid::isInvalid($value)) {
            $field->addTypeError($value, 'date/time');
        }
        return $value;
    }
protected function validateDatetime ( $ value , ValidationField $ field ) { if ( $ value instanceof \ DateTimeInterface ) { // do nothing, we're good } elseif ( is_string ( $ value ) && $ value !== '' && ! is_numeric ( $ value ) ) { try { $ dt = new \ DateTimeImmutable ( $ value ) ; if ( $ dt ) { $ value = $ dt ; } else { $ value = null ; } } catch ( \ Throwable $ ex ) { $ value = Invalid :: value ( ) ; } } elseif ( is_int ( $ value ) && $ value > 0 ) { try { $ value = new \ DateTimeImmutable ( '@' . ( string ) round ( $ value ) ) ; } catch ( \ Throwable $ ex ) { $ value = Invalid :: value ( ) ; } } else { $ value = Invalid :: value ( ) ; } if ( Invalid :: isInvalid ( $ value ) ) { $ field -> addTypeError ( $ value , 'date/time' ) ; } return $ value ; }
Validate a date time.

@param mixed $value The value to validate.
@param ValidationField $field The validation results to add.
@return \DateTimeInterface|Invalid Returns the cleaned value or **null** if it isn't valid.
Validate a date time .