diff --git a/src/DateTimes.php b/src/DateTimes.php index ac6bfef..ad42850 100644 --- a/src/DateTimes.php +++ b/src/DateTimes.php @@ -35,9 +35,7 @@ final public static function from( } } - throw new InvalidTypeException( - 'Value ' . $value . ' must be string in ' . DateTimeFormat::DATETIME . ' format' - ); + throw InvalidTypeException::typeError(DateTimeFormat::DATETIME . ' format', $value); } /** diff --git a/src/Dates.php b/src/Dates.php index 19eb209..a171daf 100644 --- a/src/Dates.php +++ b/src/Dates.php @@ -24,9 +24,7 @@ final public static function from( } } - throw new InvalidTypeException( - 'Value ' . $value . ' must be string in ' . DateTimeFormat::DATE . ' format' - ); + throw InvalidTypeException::typeError(DateTimeFormat::DATE . ' format', $value); } /** diff --git a/tests/DateTimesTest.phpt b/tests/DateTimesTest.phpt index a94e3cf..c3a4b3b 100644 --- a/tests/DateTimesTest.phpt +++ b/tests/DateTimesTest.phpt @@ -43,6 +43,19 @@ final class DateTimesTest extends TestCase InvalidTypeException::class ); + Assert::throws( + static function (): void { + DateTimes::from( + [ + 'date' => '1979-02-23 00:00:00.000000', + 'timezone' => 'Europe/Prague', + 'timezone_type' => 3, + ] + ); + }, + InvalidTypeException::class + ); + $d = DateTimes::from('2000-01-01 00:00:00.123456'); Assert::equal('2000-01-01 00:00:00', DateTimeFormatter::format($d)); diff --git a/tests/DatesTest.phpt b/tests/DatesTest.phpt index 7bf2fab..23d096e 100644 --- a/tests/DatesTest.phpt +++ b/tests/DatesTest.phpt @@ -41,6 +41,19 @@ final class DatesTest extends TestCase }, InvalidTypeException::class ); + + Assert::throws( + static function (): void { + Dates::from( + [ + 'date' => '1979-02-23 00:00:00.000000', + 'timezone' => 'Europe/Prague', + 'timezone_type' => 3, + ] + ); + }, + InvalidTypeException::class + ); } public function testExtract(): void