[php-src] Issue #7758: Datetime created from negative float timestamp is not monotonic (fraction part is added instead of substracted)
| From: | noreply@php.net | Date: | Sat, 11 Dec 2021 13:26:48 +0000 |
| Subject: | [php-src] Issue #7758: Datetime created from negative float timestamp is not monotonic (fraction part is added instead of substracted) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238334@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7758
Author: mvorisek
### Description
The following code:
```php
foreach ([0.5, 0, -0.5, -1, -1.5] as $ts) {
$date = new DateTime('@' . $ts);
print_r($date);
}
```
https://3v4l.org/i5hEN
Diff of current output vs expected:
```diff
DateTime Object
(
[date] => 1970-01-01 00:00:00.500000
[timezone_type] => 1
[timezone] => +00:00
)
DateTime Object
(
[date] => 1970-01-01 00:00:00.000000
[timezone_type] => 1
[timezone] => +00:00
)
DateTime Object
(
- [date] => 1970-01-01 00:00:00.500000
+ [date] => 1969-12-31 23:59:59.500000
[timezone_type] => 1
[timezone] => +00:00
)
DateTime Object
(
[date] => 1969-12-31 23:59:59.000000
[timezone_type] => 1
[timezone] => +00:00
)
DateTime Object
(
- [date] => 1969-12-31 23:59:59.500000
+ [date] => 1969-12-31 23:59:58.500000
[timezone_type] => 1
[timezone] => +00:00
)
```
present since PHP 8.0, should be fixed starting this version
### PHP Version
PHP 8.0+
### Operating System
any