Skip to content

Commit

Permalink
Handle nullable date in Clock::at()
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrooo committed Jul 12, 2023
1 parent 5e92d86 commit e564f71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Ouzo/Goodies/Utilities/Clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static function now(): Clock
/** Obtains a Clock set to to a specific point. */
public static function at(?string $date): Clock
{
$date = $date ?? Strings::EMPTY;
$dateTime = new DateTime($date);
return new Clock($dateTime);
}
Expand Down
12 changes: 11 additions & 1 deletion test/src/Ouzo/Goodies/Utilities/ClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,17 @@ public static function monthChange(): array
['2017-02-01', -1, '2017-01-01'],
['2017-03-01', -2, '2017-01-01'],
['2017-02-28', -1, '2017-01-28'],
['2018-01-31', -1, '2017-12-31']
['2018-01-31', -1, '2017-12-31'],
];
}

#[Test]
public function shouldHandleNullableDate(): void
{
//when
$clock = Clock::at(null);

//then
$this->assertNotNull($clock);
}
}

0 comments on commit e564f71

Please sign in to comment.