Skip to content

Instantly share code, notes, and snippets.

@tomgrenville
Last active March 9, 2016 15:35
Show Gist options
  • Save tomgrenville/c03a9a6e6dec0423601c to your computer and use it in GitHub Desktop.
Save tomgrenville/c03a9a6e6dec0423601c to your computer and use it in GitHub Desktop.
potential bug in carbon and chronos
<?php
// potential bug in carbon and chronos? surely the 41st of february isn't a valid date!
require 'vendor/autoload.php';
use Carbon\Carbon;
use Cake\Chronos\Chronos;
$carbonDate = Carbon::createFromFormat('d/m/Y', "41/02/1900");
$carbonDateErrors = $carbonDate->getLastErrors();
var_dump($carbonDateErrors);
// carbon returns
// array(4) {
// ["warning_count"]=>
// int(0)
// ["warnings"]=>
// array(0) {
// }
// ["error_count"]=>
// int(0)
// ["errors"]=>
// array(0) {
// }
// }
$chronosDate = Chronos::createFromFormat('d/m/Y', "41/02/1900");
$chronosDateErrors = $chronosDate->getLastErrors();
var_dump($chronosDateErrors);
// chronos returns
// array(4) {
// ["warning_count"]=>
// int(0)
// ["warnings"]=>
// array(0) {
// }
// ["error_count"]=>
// int(0)
// ["errors"]=>
// array(0) {
// }
// }
$phpDate = DateTime::createFromFormat('d/m/Y', "41/02/1900");
$phpDateErrors = $phpDate->getLastErrors();
var_dump($phpDateErrors);
// and datetime returns
// array(4) {
// ["warning_count"]=>
// int(1)
// ["warnings"]=>
// array(1) {
// [10]=>
// string(27) "The parsed date was invalid"
// }
// ["error_count"]=>
// int(0)
// ["errors"]=>
// array(0) {
// }
// }
// i have a feeling carbon and chronos should return warnings too, is seems to make sense that they would?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment