Details
Description
I'm using setDate method to parse date to get unix timestamp as follows:
$date->setDate('6/1/2008', 'M/d/Y');
It works fine on some linux platforms but has a bug on others.
If I want to parse a date with month set to one which has number of days less than 31 it adds 1 to month number.
Say, if I parse '2/10/2008', '4/15/2008', '6/22/2008' it always returns timestamp with month set to 3, 5, 7 accordingly.
I've got a solution for this bug. I've made a little modification to 'Zend_Date' class, '_date' method.
There are three lines which set the date in three steps as follows:
$date->set($parsed['year'], Zend_Date::YEAR);
$date->set($parsed['month'], Zend_Date::MONTH);
$date->set($parsed['day'], Zend_Date::DAY);
The order of the last two lines should be changed to fix the bug as follows:
$date->set($parsed['year'], Zend_Date::YEAR);
$date->set($parsed['day'], Zend_Date::DAY);
$date->set($parsed['month'], Zend_Date::MONTH);
The first line sets date to the defined year, month 12 and day 31. The second sets date to the defined day and the last sets date to the defined month.
We cannot set month before day because when we set year it sets default day number to 31. Then if we set month which has 30 days (April, June...) it switches month to the next one (May, July...) and day number to 1.
Please fix this in official release.
Where is your problem ?
Can you give us a example with code which shows the problem ? What you get, what you expected, the release, php version, os and so on...
Why should setting the 1.June respond in such a problem as you described ?
But: When you set 31.February you will ALWAYS get the 2 or 3rd May.
This is no failure but expected behaviour and documented within the manual.
I believe there is an option where you can switch off the overlapping for months.
When you set a impossible date, Zend_Date will always automatically correct this.
As your change introduces problems with existing code it will not be added to trunk.
What would you expect to get returned when you set a 32.Feburary ??