ZF-2980: compareDate() results in many calls to isYearLeapYear()
Description
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');
$s->compareDate($e);
I'm raising this just in case a mistake was made. Could be no issue.
Comments
Posted by Thomas Weidner (thomas) on 2008-03-27T10:47:02.000+0000
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.
Posted by Karol Grecki (antych) on 2008-03-27T11:08:40.000+0000
Actually I entered the year 2007 as 07 and it was parsed as I expcected
Also after changing code to
isYearLeapYear() is still called over 4000 times
Posted by Thomas Weidner (thomas) on 2008-03-27T11:12:50.000+0000
Review
Posted by Thomas Weidner (thomas) on 2008-03-27T11:48:55.000+0000
Agreed :-)
Fixed with SVN-9066... is 0 times called better for you ? ;-)
Posted by Karol Grecki (antych) on 2008-03-27T11:57:46.000+0000
Nice one, cheers
Posted by Wil Sinclair (wil) on 2008-09-02T10:39:13.000+0000
Updating for the 1.6.0 release.