Skip to content

Commit 7634386

Browse files
Fix date.
1 parent 13b532f commit 7634386

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/ValidationRules/DateValidation.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ private function validateWithFormat($value) {
3030
* @return array
3131
*/
3232
public function validate($value) {
33-
if (!is_string($value) || !is_numeric($value)) {
34-
return array("O campo deve ser um valor numérico ou string.");
35-
}
36-
if ($this->format) {
37-
return $this->validateWithFormat($value);
33+
if ($value === null) {
34+
return array();
3835
}
3936

40-
return strtotime($value) === false ? array("O campo deve ser uma data valida.") : array();
37+
return $this->validateDateStructure($value);
4138
}
4239

4340
/**
@@ -46,4 +43,21 @@ public function validate($value) {
4643
public function setParams($params) {
4744
$this->format = isset($params[0]) && is_string($params[0]) ? $params[0] : null;
4845
}
46+
47+
/**
48+
* @param $value
49+
*
50+
* @return array
51+
*/
52+
private function validateDateStructure($value) {
53+
if (!is_string($value) || !is_numeric($value)) {
54+
return array("O campo deve ser um valor numérico ou string.");
55+
}
56+
57+
if ($this->format) {
58+
return $this->validateWithFormat($value);
59+
}
60+
61+
return strtotime($value) === false ? array("O campo deve ser uma data valida.") : array();
62+
}
4963
}

src/ValidationRules/StringValidation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function getIdentifier() {
1818
* @return array
1919
*/
2020
public function validate($value) {
21-
return is_string($value) ? array() : array("O campo deve ser uma string.");
21+
return is_string($value) || $value === null ? array() : array("O campo deve ser uma string.");
2222
}
2323

2424
/**

0 commit comments

Comments
 (0)