[Form] fix support for years outside of the 32b range on x86 arch
MODIFY
DateFormatter/IntlDateFormatter.php
DateFormatter/IntlDateFormatter.php
@@ -180,7 +180,7 @@ abstract class IntlDateFormatter
/**
* Format the date/time value (timestamp) as a string.
*
- * @param int|\DateTimeInterface $timestamp The timestamp to format
+ * @param int|string|\DateTimeInterface $timestamp The timestamp to format
*
* @return string|bool The formatted value or false if formatting failed
*
@@ -192,11 +192,15 @@ abstract class IntlDateFormatter
{
// intl allows timestamps to be passed as arrays - we don't
if (\is_array($timestamp)) {
- $message = 'Only integer Unix timestamps and DateTime objects are supported';
+ $message = 'Only Unix timestamps and DateTime objects are supported';
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, $message);
}
+ if (\is_string($timestamp) && $dt = \DateTime::createFromFormat('U', $timestamp)) {
+ $timestamp = $dt;
+ }
+
// behave like the intl extension
$argumentError = null;
if (!\is_int($timestamp) && !$timestamp instanceof \DateTimeInterface) {
@@ -212,7 +216,7 @@ abstract class IntlDateFormatter
}
if ($timestamp instanceof \DateTimeInterface) {
- $timestamp = $timestamp->getTimestamp();
+ $timestamp = $timestamp->format('U');
}
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
@@ -586,8 +590,7 @@ abstract class IntlDateFormatter
*/
protected function createDateTime($timestamp)
{
- $dateTime = new \DateTime();
- $dateTime->setTimestamp($timestamp);
+ $dateTime = \DateTime::createFromFormat('U', $timestamp);
$dateTime->setTimezone($this->dateTimeZone);
return $dateTime;

MODIFY
Tests/DateFormatter/IntlDateFormatterTest.php
Tests/DateFormatter/IntlDateFormatterTest.php
@@ -72,7 +72,7 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
} catch (\Exception $e) {
$this->assertInstanceOf(MethodArgumentValueNotImplementedException::class, $e);
- $this->assertStringEndsWith('Only integer Unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
+ $this->assertStringEndsWith('Only Unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
}
}

[Form] fix support for years outside of the 32b range on x86 arch