Skip to content

Commit e3338a1

Browse files
committed
error if the input string couldn't be parsed as a date
When the Intl polyfill is used instead of the PHP intl extension, the intl_get_error_code() function always returns 0 no matter if the input string could be parsed.
1 parent 4357a19 commit e3338a1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public function reverseTransform($value)
130130
} elseif ($timestamp > 253402214400) {
131131
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
132132
throw new TransformationFailedException('Years beyond 9999 are not supported.');
133+
} elseif (false === $timestamp) {
134+
// the value couldn't be parsed but the Intl extension didn't report an error code, this
135+
// could be the case when the Intl polyfill is used which always returns 0 as the error code
136+
throw new TransformationFailedException(sprintf('"%s" could not be parsed as a date.', $value));
133137
}
134138

135139
try {

0 commit comments

Comments
 (0)