php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77001 Bug in date_add
Submitted: 2018-10-11 13:58 UTC Modified: 2018-10-11 16:00 UTC
From: binhorbsoft at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 7.2.10 OS: Linux
Private report: No CVE-ID: None
 [2018-10-11 13:58 UTC] binhorbsoft at gmail dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-11 14:18 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Type: Documentation Problem +Type: Bug -Package: *General Issues +Package: Date/time related -Assigned To: +Assigned To: cmb
 [2018-10-11 14:18 UTC] cmb@php.net
This looks like a duplicate of bug #75642.
 [2018-10-11 16:00 UTC] derick@php.net
This is fixed for PHP 7.3.0RC4, by upgrading timelib (See: #75577)
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Nov 15 03:01:25 2018 UTC