Zend Framework

compareDate() results in many calls to isYearLeapYear()

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.5.1
  • Fix Version/s: 1.6.0
  • Component/s: Zend_Date
  • Labels:
    None

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.

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Karol Grecki added a comment -

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');
$s->compareDate($e);

isYearLeapYear() is still called over 4000 times

Show
Karol Grecki added a comment - 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');
$s->compareDate($e);
isYearLeapYear() is still called over 4000 times
Hide
Thomas Weidner added a comment -

Review

Show
Thomas Weidner added a comment - Review
Hide
Thomas Weidner added a comment -

Agreed

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

Show
Thomas Weidner added a comment - Agreed Fixed with SVN-9066... is 0 times called better for you ?
Hide
Karol Grecki added a comment -

Nice one, cheers

Show
Karol Grecki added a comment - Nice one, cheers
Hide
Wil Sinclair added a comment -

Updating for the 1.6.0 release.

Show
Wil Sinclair added a comment - Updating for the 1.6.0 release.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
1h
Original Estimate - 1 hour
Remaining:
30m
Time Spent - 30 minutes Remaining Estimate - 30 minutes
Logged:
30m
Time Spent - 30 minutes Remaining Estimate - 30 minutes