예제 #1
0
 /**
  * Gets the difference of two date values in sfTime::MONTH
  *
  * @param $other mixed	timestamp, string, or sfDate object
  * @return int		the difference in the unit
  * @author Enrique Martinez <*****@*****.**>
  **/
 public function diffMonth($other)
 {
     $other_date = self::getInstance($other);
     $years_diff = $this->diffYear($other_date);
     $diff = 12 * $years_diff;
     $date_compare = new sfDate($other_date);
     $date_compare->addYear($years_diff);
     if ($other_date->cmp($this) < 0) {
         while ($date_compare->cmp($this) < 0) {
             $date_compare = new sfDate($other_date);
             $diff++;
             $date_compare->addCalendarMonth($diff);
         }
         if ($date_compare->cmp($this) > 0) {
             $diff--;
         }
     }
     if ($other_date->cmp($this) > 0) {
         while ($date_compare->cmp($this) > 0) {
             $date_compare = new sfDate($other_date);
             $diff--;
             $date_compare->subtractCalendarMonth(abs($diff));
         }
         if ($date_compare->cmp($this) < 0) {
             $diff++;
         }
     }
     return $diff;
 }