-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Closed as not planned
Copy link
Description
Description
A negative timestamp with fractions like -1.1 should result in integer -1 on calling DateTime->getTimestamp() but it results in -2.
As PHP internally handles this as an integer field storing the "seconds since epoch" (-2 in this case) plus a positive number of microseconds (9000000 in this case) means (-2 + 0.900000 = -1.1) ... I think a negative "seconds since epoch" needs to be adjusted to return the truncated seconds as integer correctly.
The following code:
<?php
$dt1 = new DateTime('@1.1');
$dt2 = new DateTime('@-1.1');
var_dump($dt1, $dt1->getTimestamp());
var_dump($dt2, $dt2->getTimestamp());Resulted in this output:
object(DateTime)#1 (3) {
["date"]=>
string(26) "1970-01-01 00:00:01.100000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
int(1)
object(DateTime)#2 (3) {
["date"]=>
string(26) "1969-12-31 23:59:58.900000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
int(-2)
But I expected this output instead:
object(DateTime)#1 (3) {
["date"]=>
string(26) "1970-01-01 00:00:01.100000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
int(1)
object(DateTime)#2 (3) {
["date"]=>
string(26) "1969-12-31 23:59:58.900000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
int(-1)
PHP Version
PHP 8.2.x
Operating System
No response