2008年11月14日星期五

[fw-core] Problem of Zend_Date::addDay

Hi All:

I found a problem of Zend_Date:

[code]
<?php
require_once 'Zend/Date.php';

date_default_timezone_set('Asia/Taipei');

$today = new Zend_Date();
$today->setDate('2008-11-21');

$expireDateTime = clone $today;
$expireDateTime->addDay(40);

echo $expireDateTime->toString('YYYY-MM-dd');

// expect : 2008-12-31
// actual : 2009-12-31
[/code]

When I used addDay method to add $today to year 2001~2008, month 12, and day 29~31, the year would be wrong.

For Example:

2008-11-09 + 50(days) = 2009-12-29 (wrong)
2008-11-01 + 50(days) = 2008-12-21 (right)
2007-11-21 + 40(days) = 2008-12-31 (wrong)
2007-11-11 + 50(days) = 2008-12-31 (wrong)
2009-11-11 + 50(days) = 2009-12-31 (right)
2009-11-21 + 40(days) = 2008-12-31 (right)
2000-11-21 + 40(days) = 2000-12-31 (right)
2001-11-21 + 40(days) = 2002-12-31 (wrong)
...

Is this a bug? Or missing out something?

Please forget my poor english.



Jace Ju

没有评论: