php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75038 wrong result of Datetime::add
Submitted: 2017-08-04 17:24 UTC Modified: 2017-10-24 05:24 UTC
From: marco dot delcorto at genesi-software dot it Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: 5.6.31 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marco dot delcorto at genesi-software dot it
New email:
PHP Version: OS:

 

 [2017-08-04 17:24 UTC] marco dot delcorto at genesi-software dot it
Description:
------------
---
From manual page: http://www.php.net/datetime.add
---
using the script in the example:
  $date = new DateTime('2369-12-30');
  $date->add(new DateInterval('P1D'));
  echo $date->format('Y-m-d');
the result is '2370-01-00' (wrong), instead of '2369-12-31'

Same problem if we use:
  $dateW2 = new DateTime('2369-12-31');
  echo date_format($dateW2, 'Y-m-d');
the result is '2370-01-00' (wrong), instead of '2369-12-31'


Test script:
---------------
$date = new DateTime('2369-12-30');
$date->add(new DateInterval('P1D'));
echo $date->format('Y-m-d') . "\n";

$dateW2 = new DateTime('2369-12-31');
echo date_format($dateW2, 'Y-m-d');




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-11 12:14 UTC] jhdxr@php.net
-Summary: datetime error +Summary: wrong result of Datetime::add -Status: Open +Status: Verified -Package: *General Issues +Package: Date/time related
 [2017-08-11 12:14 UTC] jhdxr@php.net
https://3v4l.org/VlkYR
 [2017-08-11 13:10 UTC] derick@php.net
This is a bug in timelib - in the formatting of timestamps:

derick@singlemalt:~/dev/timelib/tests $ ./tester-create-ts "2369-12-31" "" "UTC"
TS: 12622694400 | 2369-12-31 00:00:00 UTC UTC

derick@singlemalt:~/dev/timelib/tests $ ./tester-render-ts 12622694400 "UTC"
TYPE: 3 TS: 12622694400 | 2370-01-00 00:00:00 UTC UTC

I have filed a bug upstream:
https://github.com/derickr/timelib/issues/17
 [2017-08-11 13:11 UTC] derick@php.net
-Assigned To: +Assigned To: derick
 [2017-10-24 05:24 UTC] kalle@php.net
-Status: Verified +Status: Assigned
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC