Skip to content

Commit 6ef2bcd

Browse files
author
bahman
committed
feat(validators): add date validation method
- Implemented date validation using DateTime::createFromFormat - Supports both 'Y-m-d\TH:i:s.v\Z' and ATOM formats - Returns boolean indicating if value is valid date Signed-off-by: bahman <bja@adlas.at>
1 parent 9e02c13 commit 6ef2bcd

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/Validators/BaseValidator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ private function not_empty($value): bool {
107107
return !empty($value);
108108
}
109109

110+
/**
111+
* @param $value
112+
* @return bool
113+
*/
114+
private function date(string $value): bool {
115+
$date = \DateTime::createFromFormat('Y-m-d\TH:i:s.v\Z', $value)
116+
?: \DateTime::createFromFormat(\DateTime::ATOM, $value);
117+
return $date !== false;
118+
}
119+
110120
/**
111121
* @throws Exception
112122
*/

0 commit comments

Comments
 (0)