Skip to content

Commit

Permalink
fix(simple-date): added fix for simple date deserialization (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali214 authored Jan 17, 2024
1 parent 4610b37 commit 0ccfb70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function fromSimpleDate(?string $date): ?DateTime
}
$x = DateTime::createFromFormat(static::SIMPLE_DATE, $date);
if ($x instanceof DateTime) {
return $x;
return $x->setTime(0, 0);
}
throw new InvalidArgumentException('Incorrect format.');
}
Expand Down
6 changes: 6 additions & 0 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ public function testFromSimpleDateString()
null], DateHelper::toSimpleDate2DArray($res));
}

public function testFromSimpleDateStringTimeInfo()
{
$date = DateHelper::fromSimpleDate('2024-01-16');
$this->assertEquals(strtotime('2024-01-16'), $date->getTimestamp());
}

public function testFromRFC1123DateString()
{
$this->assertNull(DateHelper::fromRfc1123DateTimeMapOfArray(null));
Expand Down

0 comments on commit 0ccfb70

Please sign in to comment.