Horde_Date::compareDate PHP Method

compareDate() public method

Compares this date to another date object to see which one is greater (later). Assumes that the dates are in the same timezone.
public compareDate ( mixed $other ) : integer
$other mixed The date to compare to.
return integer == 0 if they are on the same date >= 1 if $this is greater (later) <= -1 if $other is greater (later)
    public function compareDate($other)
    {
        if (!$other instanceof Horde_Date) {
            $other = new Horde_Date($other);
        }
        if ($this->_year != $other->year) {
            return $this->_year - $other->year;
        }
        if ($this->_month != $other->month) {
            return $this->_month - $other->month;
        }
        return $this->_mday - $other->mday;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Search the database for call detail records, taking permissions into
  * consideration.
  *
  * @return array  [0] contains summary statistics; [1] is an array of the
  *                actual call records.
  * @throws Operator_Exception
  */
 public function getRecords($start, $end, $accountcode = null, $dcontext = null, $rowstart = 0, $rowlimit = 100)
 {
     // Start Date
     if (!is_a($start, 'Horde_Date')) {
         $start = new Horde_Date($start);
     }
     // End Date
     if (!is_a($end, 'Horde_Date')) {
         $end = new Horde_Date($end);
     }
     if ($start->compareDate($end) > 0) {
         throw new Operator_Exception(_("\"Start\" date must be on or before \"End\" date."));
     }
     if (empty($accountcode) || $accountcode == '%') {
         $permentry = 'operator:accountcodes';
     } else {
         $permentry = 'operator:accountcodes:' . $accountcode;
     }
     $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
     if ($GLOBALS['registry']->isAdmin() || $perms->hasPermission('operator:accountcodes', $GLOBALS['registry']->getAuth(), Horde_Perms::READ) || $perms->hasPermission($permentry, $GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
         return $this->_getRecords($start, $end, $accountcode, $dcontext, $rowstart, $rowlimit);
     }
     throw new Operator_Exception(_("You do not have permission to view call detail records for that account code."));
 }
All Usage Examples Of Horde_Date::compareDate