src/TypeTrait/DateTimeTypeTrait.php
private function validateDateTime($value): void
    {
        try {
            if(
                is_a($value, DateTime::class) ||
                is_null($value) ||
                $value === 'now'
            ) {
                // Expected and valid values, no need to attempt conversion
            } else {
                if($this->isUnixTimestamp($value)) {
                    // Try making a DateTime with a UNIX Timestamp from a string
                    DateTime::createFromFormat("U.u", $this->unixTimestampAsUuFormat($value));
                } else {
                    // Try making a DateTime with whatever remains
                    new DateTime($value);
                }
            }
        } catch (Exception $e) {
            throw new TypeValidationException('Attempted to pass non-date[time] value to date[time] type');
        }
    }
private function validateDateTime($value): void
    {
        try {
            if(
                is_a($value, DateTime::class) ||
                is_null($value) ||
                $value === 'now'
            ) {
                // Expected and valid values, no need to attempt conversion
            } else {
                if($this->isUnixTimestamp($value)) {
                    // Try making a DateTime with a UNIX Timestamp from a string
                    DateTime::createFromFormat("U.u", $this->unixTimestampAsUuFormat($value));
                } else {
                    // Try making a DateTime with whatever remains
                    new DateTime($value);
                }
            }
        } catch (Exception $e) {
            throw new TypeValidationException('Attempted to pass non-date[time] value to date[time] type');
        }
    }
private function validateDateTime ( $ value ) : void { try { if ( is_a ( $ value , DateTime :: class ) || is_null ( $ value ) || $ value === 'now' ) { // Expected and valid values, no need to attempt conversion } else { if ( $ this -> isUnixTimestamp ( $ value ) ) { // Try making a DateTime with a UNIX Timestamp from a string DateTime :: createFromFormat ( "U.u" , $ this -> unixTimestampAsUuFormat ( $ value ) ) ; } else { // Try making a DateTime with whatever remains new DateTime ( $ value ) ; } } } catch ( Exception $ e ) { throw new TypeValidationException ( 'Attempted to pass non-date[time] value to date[time] type' ) ; } }
Validates a value as a nullable value that can be cast to DateTime

@param $value
@throws TypeValidationException
Validates a value as a nullable value that can be cast to DateTime