php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73294 DateTime wrong when date string is negative
Submitted: 2016-10-11 16:42 UTC Modified: 2017-02-12 20:20 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: andrmoel at googlemail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.0.11 OS: Ubuntu
Private report: No CVE-ID: None
 [2016-10-11 16:42 UTC] andrmoel at googlemail dot com
Description:
------------
When you run the test script, the second outpot is parsed false. It returns the date minus one day. Maybe this error occures with other strings also.

Test script:
---------------
<?php

$dt = new DateTime('-1999-06-22 00:00:00');
echo "\nThis should be -1999-06-22 00:00:00 -> " . $dt->format('Y-m-d H:i:s');

$dt = new DateTime('-1916-06-22 00:00:00');
echo "\nThis should be -1916-06-22 00:00:00 -> " . $dt->format('Y-m-d H:i:s');

Expected result:
----------------
This should be -1999-06-22 00:00:00 -> -1999-06-22 00:00:00
This should be -1916-06-22 00:00:00 -> -1916-06-22 00:00:00

Actual result:
--------------
This should be -1999-06-22 00:00:00 -> -1999-06-22 00:00:00
This should be -1916-06-22 00:00:00 -> -1916-06-21 00:00:00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-12 17:55 UTC] derick@php.net
I have a fix and test case for this, which I'll merge when I make a new timelib release (shortly).
 [2017-02-12 20:20 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2017-02-12 20:20 UTC] derick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC