示例#1
0
文件: Date.php 项目: fredcido/simuweb
 /**
  *
  * @param Zend_Date $iniDate
  * @return int
  */
 public static function getMonth(Zend_Date $iniDate, $now = null)
 {
     $date = $now ? $now : new Zend_Date();
     $difference = $date->sub($iniDate);
     $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND);
     $measure->convertTo(Zend_Measure_Time::MONTH);
     return round($measure->getValue());
 }
示例#2
0
 protected function getDiff(Zend_Date $timeThen, $timeNow = null)
 {
     if (!$timeNow instanceof Zend_Date) {
         $timeNow = new Zend_Date();
     }
     $difference = $timeNow->isLater($timeThen) ? $timeNow->sub($timeThen) : $timeThen->sub($timeNow);
     //$difference = $timeNow->sub($timeThen);
     $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND);
     if ($measure->compare(new Zend_Measure_Time(0)) == 0) {
         return $measure->convertTo(Zend_Measure_Time::SECOND, 0);
     }
     $units = array('SECOND' => array('1', 's'), 'MINUTE' => array('60', 'min'), 'HOUR' => array('3600', 'h'), 'DAY' => array('86400', 'day'), 'WEEK' => array('604800', 'week'), 'MONTH' => array('2628600', 'month'), 'YEAR' => array('31536000', 'year'));
     foreach ($units as $unitId => $unit) {
         if (is_array($unit) && $unit[0] / abs($measure->getValue(-1)) > 1) {
             break;
         }
         $convertTo = $unitId;
     }
     return $measure->convertTo($convertTo, 0);
 }
示例#3
0
文件: TimeTest.php 项目: netvlies/zf
 /**
  * @group ZF-9078
  */
 public function testSetTypeOnPhpMathWithStrippedValue()
 {
     $locale = new Zend_Locale('en_US');
     $time = new Zend_Measure_Time(0, Zend_Measure_Time::SECOND);
     $time->setLocale($locale);
     $time->setType(Zend_Measure_Time::SECOND);
     $seconds = $time->getValue();
     $this->assertEquals(0, $seconds);
     $this->assertEquals(Zend_Measure_Time::SECOND, $time->getType());
 }
示例#4
0
 /**
  * Return the difference of 2 dates in seconds
  * @param $startDate
  * @param $endDate
  *
  * @return int|string
  */
 public static function getDifferenceInSeconds($startDate, $endDate)
 {
     $locale = Mage::getModel('core/locale')->getLocale();
     $start_date = new Zend_Date($startDate, 'yyyy-MM-dd HH:mm:ss', $locale);
     $end_date = new Zend_Date($endDate, 'yyyy-MM-dd HH:mm:ss', $locale);
     $difference = $end_date->sub($start_date);
     $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND);
     return $measure->getValue();
 }
示例#5
0
 protected function autenticateLdap()
 {
     try {
         $container = Core_Registry::getContainers();
         $ldap = $container['ldap']->getPersist();
         $config = \Zend_Registry::get('configs');
         $samAccountNameQuery = "samAccountName={$this->getIdentity()}";
         /**
          * Modifica o host para o servidor secundário.
          */
         if ($this->_secondaryHost && isset($config['resources']['container']['ldap']['host']['secondary'])) {
             $options = $ldap->getOptions();
             $options['host'] = $config['resources']['container']['ldap']['host']['secondary'];
             $ldap = new Zend_Ldap($options);
         }
         $admUsr = $config['authenticate']['username'];
         $admPwd = $config['authenticate']['password'];
         $ldap->bind($admUsr, $admPwd);
         $userLdapCount = $ldap->count($samAccountNameQuery);
         if ($userLdapCount <= 0) {
             throw new \Sica_Auth_Exception('MN175');
         }
         $userLdap = current($ldap->search($samAccountNameQuery)->toArray());
         $pwdLastSetLDAPTimestamp = isset($userLdap['pwdlastset'][0]) ? $userLdap['pwdlastset'][0] : 0;
         $pwdLastSetLDAPTimestamp_div = bcdiv($pwdLastSetLDAPTimestamp, '10000000');
         $pwdLastSetLDAPTimestamp_sub = bcsub($pwdLastSetLDAPTimestamp_div, '11644473600');
         $pwdLastSetDate = new \Zend_Date($pwdLastSetLDAPTimestamp_sub, \Zend_Date::TIMESTAMP);
         $measureTime = new \Zend_Measure_Time(\Zend_Date::now()->sub($pwdLastSetDate)->toValue(), \Zend_Measure_Time::SECOND);
         $measureTime->convertTo(\Zend_Measure_Time::DAY);
         $daysLeftToChangePwd = ceil($measureTime->getValue());
         if ($daysLeftToChangePwd >= self::LDAP_MAX_PWD_LAST_SET_DAYS) {
             throw new \Sica_Auth_Exception('EXPIRED_PWD_MSG');
         }
         $ldap->bind($this->getIdentity(), $this->getCredential());
         return TRUE;
     } catch (\Sica_Auth_Exception $authExc) {
         $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
         $this->_authenticateResultInfo['messages'] = $authExc->getMessage();
         return false;
     } catch (\Zend_Ldap_Exception $ldapExc) {
         $ldapCode = $ldapExc->getCode();
         $message = sprintf('[SICA-e] LDAP Error in %s: "%s"', __METHOD__, $ldapExc->getMessage());
         error_log($message);
         $message = sprintf('[Erro no LDAP] %s', $ldapExc->getMessage());
         /**
          * Se não foi possível contactar o servidor LDAP e se não
          * for uma tentativa de autenticação no servidor secundário.
          */
         if ($ldapCode == self::LDAP_CONST_CODE_CANT_CONTACT_SERVER && !$this->_secondaryHost) {
             #Tentativa de autenticação no servidor secundário.
             $this->_secondaryHost = TRUE;
             return $this->autenticateLdap();
         }
         if ($ldapCode > 0) {
             $message = sprintf('LDAP0x%02x', $ldapCode);
         }
         if (false !== strpos($ldapExc->getMessage(), self::LDAP_CONST_NT_STATUS_PASSWORD_EXPIRED)) {
             $message = 'EXPIRED_PWD_MSG';
         }
         $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_UNCATEGORIZED;
         $this->_authenticateResultInfo['messages'] = $message;
         return false;
     }
 }
示例#6
0
文件: TimeTest.php 项目: lortnus/zf1
 /**
  * test for exception unknown locale
  * expected exception
  */
 public function testTimeSetWithNoLocale()
 {
     $value = new Zend_Measure_Time('100', Zend_Measure_Time::STANDARD, 'de');
     $value->setValue('200', Zend_Measure_Time::STANDARD);
     $this->assertEquals(200, $value->getValue(), 'Zend_Measure_Time value expected to be a positive integer');
 }