Skip to content

Commit

Permalink
Merge pull request #218 from samuelgmartins/3.11.x
Browse files Browse the repository at this point in the history
Include exclamation point in month element format to prevent time-of-day related bugs
  • Loading branch information
Ocramius authored Jun 8, 2023
2 parents d0c94bd + 4cdb70e commit 193b2e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Element/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Month extends AbstractDateTime
*
* @var string
*/
protected $format = 'Y-m';
protected $format = '!Y-m';

/**
* Seed attributes
Expand Down
8 changes: 8 additions & 0 deletions test/Element/MonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace LaminasTest\Form\Element;

use DateInterval;
use DateTime;
use Laminas\Form\Element\Month as MonthElement;
use Laminas\Validator\DateStep;
use Laminas\Validator\GreaterThan;
Expand Down Expand Up @@ -81,4 +82,11 @@ public function testHTML5MonthValidation(string $value, bool $expected): void
$monthValidator = $inputSpec['validators'][0];
self::assertEquals($expected, $monthValidator->isValid($value));
}

public function testTestDayTimeReset(): void
{
$element = new MonthElement('foo');
$date = DateTime::createFromFormat($element->getFormat(), '2023-01');
self::assertEquals($date->format('d H:i:s'), '01 00:00:00');
}
}

0 comments on commit 193b2e5

Please sign in to comment.