0

So, I have the code as it follows:

$dateBase = $amount->getDate();
for ($i = 1; $i <= 3; $i++) {
    $installment = new Installment();
    if ($i == 1) {
        //do stuff
    } else {
        var_dump('1-'.$dateBase->toString());
        $dateBase->addMonth(1);
        var_dump('2-'.$dateBase->toString());
    }
    $installment->setDate($dateBase);
    $dataBase = clone $dataBase;
}

And the output is:
string(25) "1-Oct 1, 2014 12:00:00 AM"
string(25) "2-Dec 1, 2014 12:00:00 AM"
string(25) "1-Dec 1, 2014 12:00:00 AM"
string(26) "2-Jan 31, 2015 12:00:00 AM"

You can see that in the second loop(when $i=2), he adds 2 months intead of just one

EDIT1: Doeing some more research, I think there is timezone bug, i changed the code as it follows

$date = new Zend_Date('10/1/2014');
var_dump($date);
$date->addMonth(1);
var_dump($date, $dateBase);
$dateBase->addMonth(1);
var_dump($dateBase); 

and the output is at it follows:

object(Zend_Date)#3754 (8) {  
  ["_locale":"Zend_Date":private]=>  
  string(2) "en"  
  ["_fractional":"Zend_Date":private]=>  
  int(0)  
  ["_precision":"Zend_Date":private]=>  
  int(3)  
  ["_unixTimestamp":"Zend_Date_DateObject":private]=>  
  string(10) "1412114400"  
  ["_timezone":"Zend_Date_DateObject":private]=>  
  string(12) "Europe/Paris"  
  ["_offset":"Zend_Date_DateObject":private]=>  
  int(-3600)  
  ["_syncronised":"Zend_Date_DateObject":private]=>  
  int(0)  
  ["_dst":protected]=>  
  bool(true)  
}  
object(Zend_Date)#3754 (8) {  
  ["_locale":"Zend_Date":private]=>  
  string(2) "en"  
  ["_fractional":"Zend_Date":private]=>  
  int(0)  
  ["_precision":"Zend_Date":private]=>  
  int(3)  
  ["_unixTimestamp":"Zend_Date_DateObject":private]=>  
  int(1414796400)  
  ["_timezone":"Zend_Date_DateObject":private]=>  
  string(12) "Europe/Paris"  
  ["_offset":"Zend_Date_DateObject":private]=>  
  int(-3600)  
  ["_syncronised":"Zend_Date_DateObject":private]=>  
  int(0)  
  ["_dst":protected]=>  
  bool(true)  
}  

object(Zend_Date)#3755 (8) {  
    ["_locale":"Zend_Date":private]=>  
    string(2) "en"  
    ["_fractional":"Zend_Date":private]=>  
  int(0)  
  ["_precision":"Zend_Date":private]=>  
  int(3)  
  ["_unixTimestamp":"Zend_Date_DateObject":private]=>  
  string(10) "1412114400"  
  ["_timezone":"Zend_Date_DateObject":private]=>  
  string(9) "Etc/GMT-2"  
  ["_offset":"Zend_Date_DateObject":private]=>  
  int(-7200)  
  ["_syncronised":"Zend_Date_DateObject":private]=>  
  int(0)  
  ["_dst":protected]=>  
  bool(true)  
}  

object(Zend_Date)#3755 (8) {  
  ["_locale":"Zend_Date":private]=>  
  string(2) "en"  
  ["_fractional":"Zend_Date":private]=>  
  int(0)  
  ["_precision":"Zend_Date":private]=>  
  int(3)  
  ["_unixTimestamp":"Zend_Date_DateObject":private]=>  
  string(10) "1417384800"  
  ["_timezone":"Zend_Date_DateObject":private]=>  
  string(9) "Etc/GMT-2"  
  ["_offset":"Zend_Date_DateObject":private]=>  
  int(-7200)  
  ["_syncronised":"Zend_Date_DateObject":private]=>  
  int(0)  
  ["_dst":protected]=>  
bool(true)  
}  

You can see that there is no difference between $date and $dataBase date, just the timezone, but when we add one month to both, they react differently, $dateBase was added an extra month

Murilo
  • 580
  • 5
  • 21

1 Answers1

0

Zend Framework 1.12 Documentation Says Something like this:

For example, When adding one month to January 31st, people familiar with SQL will expect February 28th as the result. On the other side, people familiar with Excel and OpenOffice will expect March 3rd as the result. The problem only occurs, if the resulting month does not have the day, which is set in the original date.

Check out this Link if you dont know about this:

http://framework.zend.com/manual/1.12/en/zend.date.overview.html

Indrasinh Bihola
  • 2,094
  • 3
  • 23
  • 25