#41844 [Opn]: Format returns incorrect number of digits for negative years -0001 to -0999

From: Date: Thu, 28 Jun 2007 17:32:37 +0000
Subject: #41844 [Opn]: Format returns incorrect number of digits for negative years -0001 to -0999
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-114419@lists.php.net to get a copy of this message
 ID:               41844
 User updated by:  mattsch at gmail dot com
 Reported By:      mattsch at gmail dot com
 Status:           Open
 Bug Type:         Date/time related
 Operating System: Gentoo Linux 2007.0
 PHP Version:      5.2.3
 New Comment:

I didn't mean to link the colon:

http://en.wikipedia.org/wiki/Year_zero


Previous Comments:
------------------------------------------------------------------------

[2007-06-28 17:30:18] 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




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41844&edit=1


Thread (4 messages)

« previous php.bugs (#114419) next »