Skip to content

Commit

Permalink
Merge pull request #27 from dipcode-software/fix/dates_validation
Browse files Browse the repository at this point in the history
Fixed validation of dates
  • Loading branch information
asretux authored Apr 22, 2018
2 parents d33d6be + 498ab0c commit 81e0717
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.1.2] - 2018-04-21
### Fixed
- Validation of dates

## [2.1.1] - 2018-04-20
### Fixed
- Forced choice value to be string when marking selected
Expand Down
7 changes: 6 additions & 1 deletion src/Fields/TemporalField.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public function __construct(array $args = array())
parent::__construct($args);
}

public function isValidDate($date_original, $date_created)
{
return $date_created && $date_created->format($this->format) == '!' . $date_original;
}

public function toNative($value)
{
if (empty($value)) {
Expand All @@ -26,7 +31,7 @@ public function toNative($value)

$date = date_create_from_format($this->format, $value);

if (!$date) {
if (!$date || !$this->isValidDate($value, $date)) {
throw new ValidationError($this->error_messages['invalid'], 'invalid');
}

Expand Down

0 comments on commit 81e0717

Please sign in to comment.