Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/Helpers/CanValidateDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function isDateTime(string $format, string $value): bool

if ($this->isDateFormat($format)) {
$formattedDate = DateTime::createFromFormat(
$format,
'!' . $format,
$value,
new DateTimeZone(date_default_timezone_get())
);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Helpers/CanValidateDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public function shouldFindWhenValueIsNotDateTime(string $format, string $value):
self::assertFalse($this->isDateTime($format, $value));
}

/**
* @test isDateTime for month, when in "overflow" days (i.e. '2' when I run the test on 31st of any month)
* if PECL timecop was installed we could have used "timecop_freeze(new DateTime('2025-10-31 12:00:00'));" before the assertion and "timecop_return();" after.
* without PECL timecop this test checks the fixed bug only on 29th, 30th and 31st of every month.
*/
public function shouldFindWhenValueIsDateTimeOnOverflowDay(): void
{
self::assertTrue($this->isDateTime('m-Y', '02-2025'));
}

/**
* @return mixed[][]
*/
Expand Down