From 8350b6bd36d3a4bb3a99dfbf67e746f4f815927c Mon Sep 17 00:00:00 2001 From: Fbenas Date: Mon, 7 May 2018 15:02:39 +0100 Subject: Add some simple exception handling for bad inputs --- src/Model/Collection.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/Model/Collection.php') diff --git a/src/Model/Collection.php b/src/Model/Collection.php index 803e777..62bbf98 100644 --- a/src/Model/Collection.php +++ b/src/Model/Collection.php @@ -8,7 +8,6 @@ use Exception; use Iterator; use App\Script\Input; use DateTime; -use DateTimeZone; use Countable; /** @@ -192,19 +191,18 @@ class Collection implements ArrayAccess, Iterator, Countable if ($covers = (int) $input->getOption('c')) { $this->filterByCovers($covers); } - - - // day - delivery day (dd/mm/yy) - // time - delivery time in 24h format (hh:mm) - // location - delivery location (postcode without spaces, e.g. NW43QB) - // covers - number of people to feed } public function filterByDateTime(string $date, string $time) { $dateTime = DateTime::createFromFormat('d/m/y G:i', $date . ' ' . $time); - $dateTime->setTImezone(new DateTImeZone('Europe/London')); + if (!$dateTime) { + throw new Exception( + 'Unable to parse datetime. Required time format: `G:i` (e.g. 05:30). ' + . 'Required date format: `d/m/y` (e.g. 22/06/18)' + ); + } $out = []; foreach ($this->models as $model) { if ($model->checkDate($dateTime)) { -- cgit v1.2.3