php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41844 Format returns incorrect number of digits for negative years -0001 to -0999
Submitted: 2007-06-28 17:30 UTC Modified: 2007-07-12 19:01 UTC
From: mattsch at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.3 OS: Gentoo Linux 2007.0
Private report: No CVE-ID: None
 [2007-06-28 17:30 UTC] mattsch at gmail dot com
Description:
------------
Format returns incorrect number of digits for negative years -0001 to -0999.  See ISO 8601:2004 and http://en.wikipedia.org/wiki/Year_zero: 

The "basic" format for year 0 is the four-digit form 0000, which equals the historical year 1 BC. Several "expanded" formats are possible: -0000 and +0000, as well as five- and six-digit versions. Earlier years are also negative four-, five- or six-digit years, which have an absolute value one less than the equivalent BC year, hence -0001 = 2 BC.


Reproduce code:
---------------
<?
$date = new DateTime('2007-06-28');
$date->modify('-3006 years');
echo $date->format(DATE_ISO8601);
?>

Outputs:

-999-06-17T00:00:00-0600

Expected:

-0999-06-17T00:00:00-0600

<?
$date = new DateTime('2007-06-28');
$date->modify('-2008 years');
echo $date->format(DATE_ISO8601);
?>

Outputs:

-001-06-17T00:00:00-0600

Expected:

-0001-06-17T00:00:00-0600



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-28 17:32 UTC] mattsch at gmail dot com
I didn't mean to link the colon:

http://en.wikipedia.org/wiki/Year_zero
 [2007-07-12 19:01 UTC] derick@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC