Esempio n. 1
0
 public function testIsDateTimeFalse()
 {
     // arrange
     $array = array(null, '2014-07-01 9:00:00', time());
     // act
     // assert
     foreach ($array as $value) {
         $this->assertFalse(is_datetime($value), 'Expected value to not be identified as a DateTime.');
     }
 }
Esempio n. 2
0
 /**
  * 重写像类initWhere
  * @see Common\Model.BaseModel::initWhere()
  */
 protected function initWhere($condition)
 {
     if (!is_datetime($condition['sDate'])) {
         $condition['sDate'] = date('Y-m-1');
     }
     if (!is_datetime($condition['eDate'])) {
         $condition['eDate'] = date('Y-m-d 23:59:59', strtotime(get_month_last($condition['sDate'])));
     }
     $where['addTime'] = array('between', array(strtotime($condition['sDate']), strtotime($condition['eDate'])));
     if (!empty($condition['userName'])) {
         $where['userName'] = $condition['userName'];
     }
     if (!empty($condition['controller'])) {
         $where['controller'] = $condition['controller'];
     }
     if (!empty($condition['action'])) {
         $where['action'] = $condition['action'];
     }
     if (!empty($condition['data'])) {
         $where['data'] = array('like', '%' . $condition['data'] . '%');
     }
     return $where;
 }
Esempio n. 3
0
function t_edit($c)
{
    global $info;
    // create default value for new entries
    $s = '';
    foreach ($info as $i) {
        $n = $i['name'];
        // shortcut
        $s .= "        '{$n}' => " . field_default($i) . ",\n";
    }
    $s = substr($s, 0, -2);
    // remove trailing ","
    $c = preg_replace('/!!ZOMBIES!!/', $s, $c);
    // get title field
    $x = field_get_title_field();
    $c = preg_replace('/!!ZOMBIENAME!!/', $x['name'], $c);
    // create code for form submit field retrieval:
    $s = '';
    foreach ($info as $i) {
        $n = $i['name'];
        // shortcut
        if (is_datetime($i)) {
            $s .= "        \$zitem['{$n}'] = Zombie::getDateTime(Horde_Util::getFormData('{$n}'));\n";
        } else {
            if (is_boolean($i)) {
                $s .= "        \$zitem['{$n}'] = Horde_Util::getFormData('{$n}') ? 1 : 0 ;\n";
            } else {
                $s .= "        \$zitem['{$n}'] = Horde_Util::getFormData('{$n}');\n";
            }
        }
    }
    return preg_replace('/!!ZOMBIES2!!/', $s, $c);
}
Esempio n. 4
0
 /**
  * Compare two brazilian dates
  *
  * return 2 if the dates are equal
  * return 1 if date1 is greather than date2
  * return 0 if date2 is greather than date1
  *
  * @param  string $xdata1 date in the format dd/mm/yyyy
  * @param  string $xdata2 date in the format dd/mm/yyyy
  * @return int|boolean could be an int, could be a boolean
  */
 function brazilian_date_compare($xdate1, $xdate2)
 {
     if (is_datetime($xdate1) && is_datetime($xdate2)) {
         $date1 = brazilian_date_explode($xdate1);
         $date2 = brazilian_date_explode($xdate2);
         $timestamp1 = gmmktime(0, 0, 0, $date1['month'], $date1['day'], $date1['year']);
         $timestamp2 = gmmktime(0, 0, 0, $date2['month'], $date2['day'], $date2['year']);
         if ($timestamp1 == $timestamp2) {
             return 2;
         }
         $r = $timestamp1 > $timestamp2 ? 1 : 0;
         return $r;
     } else {
         return FALSE;
     }
 }
Esempio n. 5
0
 function usort_by(&$array, $sortBy)
 {
     if (is_string($sortBy)) {
         $field = $sortBy;
         $sortBy = function ($element) use($field) {
             if (is_object($element)) {
                 return $element->{$field};
             } elseif (is_array($element)) {
                 return $element[$field];
             } else {
                 return null;
             }
         };
     }
     usort($array, function ($a, $b) use($sortBy) {
         $aValue = $sortBy($a);
         $bValue = $sortBy($b);
         if (is_string($aValue) && is_string($bValue)) {
             return strcmp($aValue, $bValue);
         } elseif (is_number($aValue) && is_number($bValue)) {
             return numbercmp($aValue, $bValue);
         } elseif (is_datetime($aValue) && is_datetime($bValue)) {
             return datecmp($aValue, $bValue);
         }
     });
 }