From 8f3ce0ad85e8c71af5ac5bd76c558154616d8692 Mon Sep 17 00:00:00 2001 From: sheychen Date: Thu, 3 May 2018 13:43:51 +0200 Subject: [PATCH] Add date and time --- src/Input.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Input.php b/src/Input.php index 0545ed0..698d4d1 100644 --- a/src/Input.php +++ b/src/Input.php @@ -34,6 +34,18 @@ class Input extends Element{ return $this; } + public function date(): Input{ + $this->data['type'] = 'date'; + $this->data['date'] = true; + return $this; + } + + public function time(): Input{ + $this->data['type'] = 'time'; + $this->data['time'] = true; + return $this; + } + public function min(int $value) : Input{ $this->data['min'] = $value; return $this; @@ -105,6 +117,18 @@ class Input extends Element{ }else if(isset($this->data['number'])){ if($this->data['number'] == true && !ctype_digit($data)) return 'non numérique'; + }else if(isset($this->data['date'])){ + if($this->data['date'] == true){ + $d = DateTime::createFromFormat('Y-m-d', $data); + if(!$d || $d->format('Y-m-d') != $data) + return 'incorrect'; + } + }else if(isset($this->data['time'])){ + if($this->data['time'] == true){ + $t = DateTime::createFromFormat('H:i', $data); + if(!$t || $t->format('H:i') != $data) + return 'incorrect'; + } }else if(isset($this->data['min'])){ if($data < $this->data['min']) return 'trop petit';