function Rfc3339::createFromString
Try creating a DateTime instance
Parameters
string $string:
Return value
\DateTime|null
1 call to Rfc3339::createFromString()
- FormatConstraint::check in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Constraints/ FormatConstraint.php - invokes the validation of an element
File
-
vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Rfc3339.php, line 16
Class
Namespace
JsonSchemaCode
public static function createFromString($string) {
if (!preg_match(self::REGEX, strtoupper($string), $matches)) {
return null;
}
$dateAndTime = $matches[1];
$microseconds = $matches[2] ?: '.000000';
$timeZone = 'Z' !== $matches[3] ? $matches[4] . ':' . $matches[5] : '+00:00';
$dateFormat = strpos($dateAndTime, 'T') === false ? 'Y-m-d H:i:s.uP' : 'Y-m-d\\TH:i:s.uP';
$dateTime = \DateTime::createFromFormat($dateFormat, $dateAndTime . $microseconds . $timeZone, new \DateTimeZone('UTC'));
return $dateTime ?: null;
}