diff --git a/src/Exceptions/InvalidDate.php b/src/Exceptions/InvalidDate.php index e8d8832..e76b624 100644 --- a/src/Exceptions/InvalidDate.php +++ b/src/Exceptions/InvalidDate.php @@ -6,8 +6,14 @@ class InvalidDate extends InvalidArgumentException { - public static function forFormat(string $date, string $format): InvalidDate + public static function forFormat(string $date, ?string $format): InvalidDate { - return new static("Could not construct a date from `{$date}` with format `{$format}`."); + $message = "Could not construct a date from `{$date}`"; + + if ($format) { + $message .= " with format `{$format}`"; + } + + return new static($message); } }