Skip to content

Commit 8173d28

Browse files
Support DateTimeImmutable in Timestamp API Fields (#2241)
1 parent 42ca7ad commit 8173d28

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Api/TimestampShape.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(array $definition, ShapeMap $shapeMap)
2424
*/
2525
public static function format($value, $format)
2626
{
27-
if ($value instanceof \DateTime) {
27+
if ($value instanceof \DateTimeInterface) {
2828
$value = $value->getTimestamp();
2929
} elseif (is_string($value)) {
3030
$value = strtotime($value);

tests/Api/TimestampShapeTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public function formatProvider()
2222
[$t, 'rfc822', 'Tue, 05 Jan 1999 00:00:00 GMT'],
2323
[new \DateTime('january 5, 1999'), 'unixTimestamp', '915494400'],
2424
[new \DateTime('january 5, 1999'), 'iso8601', '1999-01-05T00:00:00Z'],
25-
[new \DateTime('january 5, 1999'), 'rfc822', 'Tue, 05 Jan 1999 00:00:00 GMT']
25+
[new \DateTime('january 5, 1999'), 'rfc822', 'Tue, 05 Jan 1999 00:00:00 GMT'],
26+
[new \DateTimeImmutable('january 5, 1999'), 'unixTimestamp', '915494400'],
27+
[new \DateTimeImmutable('january 5, 1999'), 'iso8601', '1999-01-05T00:00:00Z'],
28+
[new \DateTimeImmutable('january 5, 1999'), 'rfc822', 'Tue, 05 Jan 1999 00:00:00 GMT']
2629
];
2730
}
2831

0 commit comments

Comments
 (0)