xref: /PHP-8.0/ext/date/tests/bug52062.phpt (revision 95f4ee38)
1--TEST--
2Bug #52062 (large timestamps with DateTime::getTimestamp and DateTime::setTimestamp) (32 bit)
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die('skip 32-bit only');
6?>
7--INI--
8date.timezone=UTC
9--FILE--
10<?php
11$d = new DateTime('@100000000000');
12var_dump($d->format('Y-m-d H:i:s U'));
13try {
14    var_dump($d->getTimestamp());
15} catch (\ValueError $e) {
16    echo $e->getMessage() . \PHP_EOL;
17}
18var_dump($d->format('U'));
19
20try {
21    $d->setTimestamp(100000000000);
22} catch (TypeError $e) {
23    echo $e->getMessage(), "\n";
24}
25var_dump($d->format('Y-m-d H:i:s U'));
26try {
27    var_dump($d->getTimestamp());
28} catch (\ValueError $e) {
29    echo $e->getMessage() . \PHP_EOL;
30}
31
32$i = new DateInterval('PT100000000000S');
33var_dump($i->format('%s'));
34?>
35--EXPECT--
36string(32) "5138-11-16 09:46:40 100000000000"
37Epoch doesn't fit in a PHP integer
38string(12) "100000000000"
39DateTime::setTimestamp(): Argument #1 ($timestamp) must be of type int, float given
40string(32) "5138-11-16 09:46:40 100000000000"
41Epoch doesn't fit in a PHP integer
42string(10) "1215752192"
43