Skip to content

Commit bd6fb68

Browse files
[Form] fix support for years outside of the 32b range on x86 arch
1 parent a9e1782 commit bd6fb68

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

DateFormatter/IntlDateFormatter.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static function create($locale, $datetype, $timetype, $timezone = null, $
180180
/**
181181
* Format the date/time value (timestamp) as a string.
182182
*
183-
* @param int|\DateTimeInterface $timestamp The timestamp to format
183+
* @param int|string|\DateTimeInterface $timestamp The timestamp to format
184184
*
185185
* @return string|bool The formatted value or false if formatting failed
186186
*
@@ -192,11 +192,15 @@ public function format($timestamp)
192192
{
193193
// intl allows timestamps to be passed as arrays - we don't
194194
if (\is_array($timestamp)) {
195-
$message = 'Only integer Unix timestamps and DateTime objects are supported';
195+
$message = 'Only Unix timestamps and DateTime objects are supported';
196196

197197
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, $message);
198198
}
199199

200+
if (\is_string($timestamp) && $dt = \DateTime::createFromFormat('U', $timestamp)) {
201+
$timestamp = $dt;
202+
}
203+
200204
// behave like the intl extension
201205
$argumentError = null;
202206
if (!\is_int($timestamp) && !$timestamp instanceof \DateTimeInterface) {
@@ -212,7 +216,7 @@ public function format($timestamp)
212216
}
213217

214218
if ($timestamp instanceof \DateTimeInterface) {
215-
$timestamp = $timestamp->getTimestamp();
219+
$timestamp = $timestamp->format('U');
216220
}
217221

218222
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
@@ -586,8 +590,7 @@ public function setTimeZone($timeZone)
586590
*/
587591
protected function createDateTime($timestamp)
588592
{
589-
$dateTime = new \DateTime();
590-
$dateTime->setTimestamp($timestamp);
593+
$dateTime = \DateTime::createFromFormat('U', $timestamp);
591594
$dateTime->setTimezone($this->dateTimeZone);
592595

593596
return $dateTime;

Tests/DateFormatter/IntlDateFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testFormatWithUnsupportedTimestampArgument()
7272
} catch (\Exception $e) {
7373
$this->assertInstanceOf(MethodArgumentValueNotImplementedException::class, $e);
7474

75-
$this->assertStringEndsWith('Only integer Unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
75+
$this->assertStringEndsWith('Only Unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
7676
}
7777
}
7878

0 commit comments

Comments
 (0)