Skip to content

Commit

Permalink
Null value
Browse files Browse the repository at this point in the history
  • Loading branch information
ottosmops committed Apr 3, 2024
1 parent 5a8a6df commit bfa6ac9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ValueObjects/AntonDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ final class AntonDate implements ValueObjectInterface
/**
* Returns a new AntonDate from a date-string
*
* @param string|AntonDate|DateTimeImmutable $sDate in AntonDateFormat 'Y-m-d', 'Y-m', 'Y' or '0000'
* @param string|AntonDate|DateTimeImmutable|null $sDate in AntonDateFormat 'Y-m-d', 'Y-m', 'Y' or '0000'
* with or wthout a 'ca. ' in front of the date
* @param bool|int $ca if $sDate starts with 'ca. ' or $ca is true the AntonDate contains $ca == 1
*
* @return static
*/
public static function createFromString(string|AntonDate|DateTimeImmutable $sDate, bool|int $ca = 0) : static
public static function createFromString(string|AntonDate|DateTimeImmutable|null $sDate, bool|int $ca = 0) : static
{
if ($sDate instanceof AntonDate) {
return $sDate;
Expand Down
7 changes: 7 additions & 0 deletions tests/AntonDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,11 @@ public function testGuessDateFromString() : void
$expected = '2014-04-02';
$this->assertEquals($expected, $actual);
}

public function testNullCreateFromString() : void
{
$actual = AntonDate::createFromString(null)->formatted();
$expected = 'no date';
$this->assertEquals($expected, $actual);
}
}

0 comments on commit bfa6ac9

Please sign in to comment.