Skip to content

Conversation

bburnichon
Copy link
Contributor

Using this helper class, it make it easy for clients of library to retrieve a proper instance of DateTime from their code.

$element = '2016-03-03T13:40:42Z';

$constraint = new JsonSchema\Constraints\FormatConstraint();
$constraint->check($element, (object)array('format' => 'date-time'));

if (!$constraint->isValid()) {
  throw new RuntimeException('Error in element format');
}

$dateTime = JsonSchema\Rfc3339::createFromString($element);

If you do not want to fully check constraint, JsonSchema\Rfc3339::createFromString() will return null for invalid strings

@bburnichon bburnichon changed the title add rfc339 helper class add rfc3339 helper class Mar 3, 2016
@bburnichon
Copy link
Contributor Author

ping @justinrainbow @bighappyface

@bighappyface
Copy link
Collaborator

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants