ZF-2980: compareDate() results in many calls to isYearLeapYear()


I was profiling my app and noticed what looks like an excessive number of calls to this function.

This simple code results in 4018 calls to isYearLeapYear()

$s = new Zend_Date('311207', 'ddMMyy');
$e = new Zend_Date('090108', 'ddMMyy');

I'm raising this just in case a mistake was made. Could be no issue.


No this is NO problem or bug or mistake.

You entered the date "31.December. 7 after Christ"... the year 0007 and not 2007. Now the timestamp is calculated for the year where christ was 7 years old.

PHP can only handle dates until 1914. (negative timestamps). Zend_Date builds the timestamp for this date himself. The calculation for real historical or even astronomical dates is complicated and is done mathematically where the mentioned function is one part of this process.

When you look into the manual there is a sentence about "historical" or "astronomical" dates and performance.

Actually I entered the year 2007 as 07 and it was parsed as I expcected

$s = new Zend_Date('311207', 'ddMMyy');
echo $s; //31 Dec 2007 00:00:00

Also after changing code to

$s = new Zend_Date('31122007', 'ddMMyyyy');
$e = new Zend_Date('09012008', 'ddMMyyyy');

isYearLeapYear() is still called over 4000 times


Agreed :-)

Fixed with SVN-9066... is 0 times called better for you ? ;-)

Nice one, cheers

Updating for the 1.6.0 release.