Skip to content

Commit 193b2e5

Browse files
authored
Merge pull request #218 from samuelgmartins/3.11.x
Include exclamation point in month element format to prevent time-of-day related bugs
2 parents d0c94bd + 4cdb70e commit 193b2e5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: src/Element/Month.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Month extends AbstractDateTime
1616
*
1717
* @var string
1818
*/
19-
protected $format = 'Y-m';
19+
protected $format = '!Y-m';
2020

2121
/**
2222
* Seed attributes

Diff for: test/Element/MonthTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace LaminasTest\Form\Element;
66

77
use DateInterval;
8+
use DateTime;
89
use Laminas\Form\Element\Month as MonthElement;
910
use Laminas\Validator\DateStep;
1011
use Laminas\Validator\GreaterThan;
@@ -81,4 +82,11 @@ public function testHTML5MonthValidation(string $value, bool $expected): void
8182
$monthValidator = $inputSpec['validators'][0];
8283
self::assertEquals($expected, $monthValidator->isValid($value));
8384
}
85+
86+
public function testTestDayTimeReset(): void
87+
{
88+
$element = new MonthElement('foo');
89+
$date = DateTime::createFromFormat($element->getFormat(), '2023-01');
90+
self::assertEquals($date->format('d H:i:s'), '01 00:00:00');
91+
}
8492
}

0 commit comments

Comments
 (0)