Bug #80748 [NEW]: DateInterval wrongly counts DateTime->diff days
| From: | palansher at outlook dot com | Date: | Sat, 13 Feb 2021 20:45:25 +0000 |
| Subject: | Bug #80748 [NEW]: DateInterval wrongly counts DateTime->diff days | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-232137@lists.php.net to get a copy of this message | ||
From: palansher at outlook dot com
Operating system: ubuntu 18.04
PHP version: Irrelevant
Package: Date/time related
Bug Type: Bug
Bug description:DateInterval wrongly counts DateTime->diff days
Description:
------------
DateTime->diff returns different days, depending on how many seconds
passed from midnight on a target date.
This behaviour is independent of timezone settings.
Tested on PHP 7.2-7.4
The bug doesn't appear if you use short period:
<?php
$beforDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-01
00:00:00');
$afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-08
00:00:43');
$dtInterval = $beforDate->diff($afterDate);
$daysPassed = $dtInterval->days;
echo "days passed if target date have 42 seconds from midnight:
$daysPassed" . PHP_EOL;
$afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-08
00:00:43');
$dtInterval = $beforDate->diff($afterDate);
$daysPassed = $dtInterval->days;
echo "days passed if target date have 43 seconds from midnight:
$daysPassed" . PHP_EOL;
Test script:
---------------
<?php
$beforDate=DateTime::createFromFormat('Y-m-d G:i:s', '1900-01-01
00:00:00');
$afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '2021-01-08
00:00:42');
$dtInterval = $beforDate->diff($afterDate);
$daysPassed = $dtInterval->days;
echo "days passed if target date have 42 seconds from midnight:
$daysPassed" . PHP_EOL;
$afterDate=DateTime::createFromFormat('Y-m-d G:i:s', '2021-01-08
00:00:43');
$dtInterval = $beforDate->diff($afterDate);
$daysPassed = $dtInterval->days;
echo "days passed if target date have 43 seconds from midnight:
$daysPassed" . PHP_EOL;
Expected result:
----------------
days passed: 44201
Actual result:
--------------
days passed: 44202
--
Edit bug report at https://bugs.php.net/bug.php?id=80748&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80748&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80748&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80748&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80748&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80748&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80748&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80748&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80748&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80748&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80748&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80748&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80748&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80748&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80748&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80748&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80748&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80748&r=mysqlcfg