Doc #77202 [NEW]: DateInterval compare unpredictable result
| From: | thomas dot wanka at gmx dot net | Date: | Mon, 26 Nov 2018 08:53:54 +0000 |
| Subject: | Doc #77202 [NEW]: DateInterval compare unpredictable result | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-16171@lists.php.net to get a copy of this message | ||
From: thomas dot wanka at gmx dot net
Operating system: Linux
PHP version: 7.2.12
Package: Date/time related
Bug Type: Documentation Problem
Bug description:DateInterval compare unpredictable result
Description:
------------
The result if compare operator on two DateInterval objects is
unpredictable.
See code in the "test script" section:
the result of the if() statement depends on the code before. If, for
instance, you print the DateInterval, the internal structure seems to
change, and the result is correct. Otherwise, the result is not correct.
The system should output an error or a warning if the compare operater
is not fully implemented.
Test script:
---------------
<?php
$old = DateTime::createFromFormat('Y-m-d H:i:s', '2018-11-26 09:29:00');
// constant here for demo only, i read datetime field from database
$now = new DateTime('now',new DateTimeZone('Europe/Berlin'));
$maxdiff = new DateInterval('PT30M');
$actualDiff = $now->diff($old);
// echo "<pre>"; print_r($now); echo "</pre><br />";
// echo "<pre>"; print_r($maxdiff ); echo "</pre><br />";
if ($actualDiff>$maxDiff) echo "time is up" else echo "just wait";
?>
Expected result:
----------------
throw an error if an nvalid operator ist used
minimum request: add information about this behauviour into
documentation of DateInterval
Actual result:
--------------
operator is performed, result is unpredictable
--
Edit bug report at https://bugs.php.net/bug.php?id=77202&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77202&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77202&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77202&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77202&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77202&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77202&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77202&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77202&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77202&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77202&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77202&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77202&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77202&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77202&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77202&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77202&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77202&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77202&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77202&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77202&r=mysqlcfg