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

Commit 0d7e6b6

Browse files
committed
Merge branch 'feature/172' into develop
Close #172 Fixes #170 Fixes #168
2 parents f003652 + 78fed36 commit 0d7e6b6

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ All notable changes to this project will be documented in this file, in reverse
2929
binding values in a fieldset will correctly identify the elements in the
3030
provided data.
3131

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

3440
### Added

src/Element/DateTime.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected function getValidators()
135135
throw new InvalidArgumentException(sprintf(
136136
'%1$s expects "min" to conform to %2$s; received "%3$s"',
137137
__METHOD__,
138-
static::DATETIME_FORMAT,
138+
$this->format,
139139
$this->attributes['min']
140140
));
141141
}
@@ -153,7 +153,7 @@ protected function getValidators()
153153
throw new InvalidArgumentException(sprintf(
154154
'%1$s expects "max" to conform to %2$s; received "%3$s"',
155155
__METHOD__,
156-
static::DATETIME_FORMAT,
156+
$this->format,
157157
$this->attributes['max']
158158
));
159159
}
@@ -226,7 +226,7 @@ public function getInputSpecification()
226226
private function valueIsValidDateTimeFormat($value)
227227
{
228228
return PhpDateTime::createFromFormat(
229-
static::DATETIME_FORMAT,
229+
$this->format,
230230
$value
231231
) instanceof DateTimeInterface;
232232
}

src/Element/Month.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class Month extends DateTime
1818

1919
const DATETIME_FORMAT = 'Y-m';
2020

21+
/**
22+
* A valid format string accepted by date()
23+
*
24+
* @var string
25+
*/
26+
protected $format = self::DATETIME_FORMAT;
27+
2128
/**
2229
* Seed attributes
2330
*

test/Element/DateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public function testCorrectFormatPassedToDateValidator()
125125
{
126126
$element = new DateElement('foo');
127127
$element->setAttributes([
128-
'min' => '2012-01-01',
129-
'max' => '2012-12-31',
128+
'min' => '01-01-2012',
129+
'max' => '31-12-2012',
130130
]);
131131
$element->setFormat('d-m-Y');
132132

0 commit comments

Comments
 (0)