{"action":"created","issue":{"url":"https://api.github.com/repos/kevinkhill/lavacharts/issues/69","labels_url":"https://api.github.com/repos/kevinkhill/lavacharts/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/kevinkhill/lavacharts/issues/69/comments","events_url":"https://api.github.com/repos/kevinkhill/lavacharts/issues/69/events","html_url":"https://github.com/kevinkhill/lavacharts/issues/69","id":113906086,"number":69,"title":"InvalidDateTimeFormat Exception when $dateTimeFormat is NULL","user":{"login":"SendDerek","id":469263,"avatar_url":"https://avatars.githubusercontent.com/u/469263?v=3","gravatar_id":"","url":"https://api.github.com/users/SendDerek","html_url":"https://github.com/SendDerek","followers_url":"https://api.github.com/users/SendDerek/followers","following_url":"https://api.github.com/users/SendDerek/following{/other_user}","gists_url":"https://api.github.com/users/SendDerek/gists{/gist_id}","starred_url":"https://api.github.com/users/SendDerek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SendDerek/subscriptions","organizations_url":"https://api.github.com/users/SendDerek/orgs","repos_url":"https://api.github.com/users/SendDerek/repos","events_url":"https://api.github.com/users/SendDerek/events{/privacy}","received_events_url":"https://api.github.com/users/SendDerek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-28T19:39:43Z","updated_at":"2015-10-28T23:13:25Z","closed_at":null,"body":"I have an InvalidDateTimeFormat error being thrown using Lavacharts 3.0.x-dev and the example code provided in the README.\r\n\r\n    $stocksTable = Lava::DataTable();\r\n\r\n    $stocksTable->addDateColumn('Day of Month')\r\n        ->addNumberColumn('Projected')\r\n        ->addNumberColumn('Official');\r\n\r\n    // Random Data For Example\r\n    for ($a = 1; $a < 30; $a++)\r\n    {\r\n        $rowData = [\r\n            \"2014-8-$a\", rand(800,1000), rand(800,1000)\r\n        ];\r\n\r\n        $stocksTable->addRow($rowData);\r\n    }\r\n\r\nError details:\r\n\r\n    InvalidDateTimeFormat in DateCell.php line 60:\r\n    NULL is invalid, must be a datetime format string which Carbon can use.\r\n\r\n    1. in DateCell.php line 60\r\n    2. at DateCell::parseString('2014-8-1', null) in RowFactory.php line 84\r\n    3. at RowFactory->create(array('2014-8-1', '901', '931')) in DataTable.php line 558\r\n    4. at DataTable->addRow(array('2014-8-1', '901', '931')) in IndexController.php line 38\r\n    5. at IndexController->index()\r\n\r\nLooking at line 60, we're defaulting to an empty string, but don't try to account for what happens when $dateTimeString is a null object:\r\nhttps://github.com/kevinkhill/lavacharts/blob/3.0/src/DataTables/Cells/DateCell.php#L60\r\n\r\nWe're getting the null object in the first place from line 83 in RowFactory.php:\r\nhttps://github.com/kevinkhill/lavacharts/blob/3.0/src/DataTables/Rows/RowFactory.php#L83\r\n\r\nA quick fix is to do a quick check for $dateTimeFormat.  If it exists, then pass it along, otherwise, pass along an empty string.\r\n\r\n      foreach ($valueArray as $index => $cell) {\r\n           if ((bool) preg_match('/date|datetime|timeofday/', $columnTypes[$index]) === true) {\r\n               if ($cell instanceof Carbon) {\r\n                   $rowData[] = new DateCell($cell);\r\n               } else {\r\n    -               $rowData[] = DateCell::parseString($cell, $dateTimeFormat);\r\n    +               $rowData[] = DateCell::parseString($cell, $dateTimeFormat ? $dateTimeFormat : '');\r\n               }\r\n           } else {\r\n               $rowData[] = $cell;\r\n           }\r\n    -   }\r\n    +  }\r\n\r\nI wonder why PHP didn't complain/warn about an undeclared variable $dateTimeFormat in use?  Maybe this was by design?\r\n\r\nExpected Behavior:  To execute sample code normally without any exceptions thrown.\r\nActual Behavior:  Exception thrown when example code is executed.\r\nSTRs:\r\n1.) In Laravel, hijack or create a Controller\r\n2.) Copy/paste code above\r\n3.) Run controller by browsing to url that triggers controller method or by some other means.  Artisan tinker maybe?"},"comment":{"url":"https://api.github.com/repos/kevinkhill/lavacharts/issues/comments/152025241","html_url":"https://github.com/kevinkhill/lavacharts/issues/69#issuecomment-152025241","issue_url":"https://api.github.com/repos/kevinkhill/lavacharts/issues/69","id":152025241,"user":{"login":"kevinkhill","id":266076,"avatar_url":"https://avatars.githubusercontent.com/u/266076?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinkhill","html_url":"https://github.com/kevinkhill","followers_url":"https://api.github.com/users/kevinkhill/followers","following_url":"https://api.github.com/users/kevinkhill/following{/other_user}","gists_url":"https://api.github.com/users/kevinkhill/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinkhill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinkhill/subscriptions","organizations_url":"https://api.github.com/users/kevinkhill/orgs","repos_url":"https://api.github.com/users/kevinkhill/repos","events_url":"https://api.github.com/users/kevinkhill/events{/privacy}","received_events_url":"https://api.github.com/users/kevinkhill/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T23:13:25Z","updated_at":"2015-10-28T23:13:25Z","body":"Thank you for helping out, I appreciate your contribution. Your pull request has been merged "}}