Skip to content

Commit

Permalink
Merge pull request #513 from helsingborg-stad/fix/handle-null-dates
Browse files Browse the repository at this point in the history
fix: handle null dates
  • Loading branch information
NiclasNorin authored Feb 6, 2025
2 parents 8cb9b0c + a4eea83 commit 5fce0a1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source/php/Component/Date/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ComponentLibrary\Component\Date\Utilities\DateFormatter;
use ComponentLibrary\Component\Date\Utilities\TimeSinceFormatter;
use ComponentLibrary\Component\Date\Config\DateConfig;
use Exception;

/**
* Class Date
Expand Down Expand Up @@ -104,11 +105,17 @@ public function sanitizeReturn(): array
*
* @return int
*/
private function inputDateToTimestamp(string|int $timestamp): int|\Exception
private function inputDateToTimestamp(null|string|int $timestamp): int|\Exception
{
return is_int($timestamp)
? $timestamp
: $this->strToTime($timestamp);
if (is_null($timestamp)) {
return new Exception('Date Component: No date provided.');
}

if(is_int($timestamp)) {
return $timestamp;
}

return $this->strToTime($timestamp);
}

/**
Expand Down

0 comments on commit 5fce0a1

Please sign in to comment.