class Rfc3339
Hierarchy
- class \JsonSchema\Rfc3339
Expanded class hierarchy of Rfc3339
1 file declares its use of Rfc3339
- FormatConstraint.php in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Constraints/ FormatConstraint.php
File
-
vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Rfc3339.php, line 5
Namespace
JsonSchemaView source
class Rfc3339 {
const REGEX = '/^(\\d{4}-\\d{2}-\\d{2}[T ]{1}\\d{2}:\\d{2}:\\d{2})(\\.\\d+)?(Z|([+-]\\d{2}):?(\\d{2}))$/';
/**
* Try creating a DateTime instance
*
* @param string $string
*
* @return \DateTime|null
*/
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;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Rfc3339::createFromString | public static | function | Try creating a DateTime instance |
Rfc3339::REGEX | constant |