Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/172' into develop
Browse files Browse the repository at this point in the history
Close #172
Fixes #170
Fixes #168
  • Loading branch information
weierophinney committed Dec 6, 2017
2 parents f003652 + 78fed36 commit 0d7e6b6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ All notable changes to this project will be documented in this file, in reverse
binding values in a fieldset will correctly identify the elements in the
provided data.

- [#172](https://github.com/zendframework/zend-form/pull/172) fixes the
`DateTime` element such that it no longer attempts to use its
`DATETIME_FORMAT` constant, but, rather, the value of the `$format` property,
when representing the element; this change allows developers to override the
format, which was the original intention.

## 2.10.3 - TBD

### Added
Expand Down
6 changes: 3 additions & 3 deletions src/Element/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function getValidators()
throw new InvalidArgumentException(sprintf(
'%1$s expects "min" to conform to %2$s; received "%3$s"',
__METHOD__,
static::DATETIME_FORMAT,
$this->format,
$this->attributes['min']
));
}
Expand All @@ -153,7 +153,7 @@ protected function getValidators()
throw new InvalidArgumentException(sprintf(
'%1$s expects "max" to conform to %2$s; received "%3$s"',
__METHOD__,
static::DATETIME_FORMAT,
$this->format,
$this->attributes['max']
));
}
Expand Down Expand Up @@ -226,7 +226,7 @@ public function getInputSpecification()
private function valueIsValidDateTimeFormat($value)
{
return PhpDateTime::createFromFormat(
static::DATETIME_FORMAT,
$this->format,
$value
) instanceof DateTimeInterface;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Element/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class Month extends DateTime

const DATETIME_FORMAT = 'Y-m';

/**
* A valid format string accepted by date()
*
* @var string
*/
protected $format = self::DATETIME_FORMAT;

/**
* Seed attributes
*
Expand Down
4 changes: 2 additions & 2 deletions test/Element/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public function testCorrectFormatPassedToDateValidator()
{
$element = new DateElement('foo');
$element->setAttributes([
'min' => '2012-01-01',
'max' => '2012-12-31',
'min' => '01-01-2012',
'max' => '31-12-2012',
]);
$element->setFormat('d-m-Y');

Expand Down

0 comments on commit 0d7e6b6

Please sign in to comment.