Doc #77001 [NEW]: Bug in date_add
From: binhorbsoft at gmail dot com
Operating system: Linux
PHP version: 7.2.10
Package: *General Issues
Bug Type: Documentation Problem
Bug description:Bug in date_add
Description:
------------
---
From manual page: http://www.php.net/datetime.add
---
If the sum has fraction of a second, the method fails if the result of
the fraction is exactly one second. In other cases, it works well.
Test script:
---------------
<?php
$objDataHora = date_create("2017-12-31T23:59:59.200");
$objIntervalo = new DateInterval("PT0S");
$objIntervalo->f = 0.700;
$objDataHora = date_add($objDataHora, $objIntervalo);
$strDataHora = date_format($objDataHora, "Y-m-d\TH:i:s.v");
echo("<p>$strDataHora</p>\n"); // 2017-12-31T23:59:59.900 - it's OK, the
sum is correct
$objDataHora = date_create("2017-12-31T23:59:59.400");
$objIntervalo = new DateInterval("PT0S");
$objIntervalo->f = 0.700;
$objDataHora = date_add($objDataHora, $objIntervalo);
$strDataHora = date_format($objDataHora, "Y-m-d\TH:i:s.v");
echo("<p>$strDataHora</p>\n"); // 2018-01-01T00:00:00.100 - it's OK, the
sum is correct
$objDataHora = date_create("2017-12-31T23:59:59.300");
$objIntervalo = new DateInterval("PT0S");
$objIntervalo->f = 0.700;
$objDataHora = date_add($objDataHora, $objIntervalo);
$strDataHora = date_format($objDataHora, "Y-m-d\TH:i:s.v");
echo("<p>$strDataHora</p>\n"); // 2017-12-31T23:59:59.1000 - it isn't
OK, the sum is incorrect!
?>
Expected result:
----------------
In third echo: 2018-01-01T00:00:00.000
Actual result:
--------------
In third echo: 2017-12-31T23:59:59.1000
--
Edit bug report at https://bugs.php.net/bug.php?id=77001&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77001&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77001&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77001&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77001&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77001&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77001&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77001&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77001&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77001&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77001&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77001&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77001&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77001&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77001&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77001&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77001&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77001&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77001&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77001&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77001&r=mysqlcfg
Thread (1 message)
- binhorbsoft at gmail dot com