DateTime[Immutable]::createFromTimestamp(float) misses support for 64bit integers or 32bit environments
Open
Nobody has claimed this yet.
Bug
Extension: date
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
$dt = DateTime::createFromFormat('U', '2147483647');
var_dump($dt);
$dt = $dt->modify('+1 second');
var_dump($dt);
$ts = $dt->format('U');
$tsf = (float)$ts;
var_dump($ts, $tsf);
$dt2 = DateTime::createFromTimestamp($tsf);
Resulted in this output:
object(DateTime)#1 (3) {
["date"]=>
string(26) "2038-01-19 03:14:07.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
object(DateTime)#1 (3) {
["date"]=>
string(26) "2038-01-19 03:14:08.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
string(10) "2147483648"
float(2147483648)
Fatal error: Uncaught DateRangeError: DateTime::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between -2147483648 and 2147483647.999999, 2.14748e+9 given
But I expected this output instead:
object(DateTime)#1 (3) {
["date"]=>
string(26) "2038-01-19 03:14:07.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
object(DateTime)#1 (3) {
["date"]=>
string(26) "2038-01-19 03:14:08.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
string(10) "2147483648"
float(2147483648)
object(DateTime)#2 (3) {
["date"]=>
string(26) "2038-01-19 03:14:08.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
PHP Version
>= PHP 8.4
Operating System
32bit environment
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DateTime::createFromTimestamp() entry point and reproduce the example on a 32-bit environment, focusing on the float value 2147483648. Done means this value is accepted and produces the expected 2038-01-19 03:14:08 DateTime instead of a DateRangeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100