示例#1
0
文件: Date.php 项目: jasmun/Noco100
 /**
  * Returns the calculated month
  *
  * @param  string                          $calc    Calculation to make
  * @param  string|integer|array|IfwPsn_Vendor_Zend_Date  $month   Month to calculate with, if null the actual month is taken
  * @param  string|IfwPsn_Vendor_Zend_Locale              $locale  Locale for parsing input
  * @return integer|IfwPsn_Vendor_Zend_Date  new time
  * @throws IfwPsn_Vendor_Zend_Date_Exception
  */
 private function _month($calc, $month, $locale)
 {
     if ($month === null) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date/Exception.php';
         throw new IfwPsn_Vendor_Zend_Date_Exception('parameter $month must be set, null is not allowed');
     }
     if ($locale === null) {
         $locale = $this->getLocale();
     }
     if ($month instanceof IfwPsn_Vendor_Zend_Date) {
         // extract month from object
         $found = $month->toString(self::MONTH_SHORT, 'iso', $locale);
     } else {
         if (is_numeric($month)) {
             $found = $month;
         } else {
             if (is_array($month)) {
                 if (isset($month['month']) === true) {
                     $month = $month['month'];
                 } else {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Date_Exception("no month given in array");
                 }
             } else {
                 $monthlist = IfwPsn_Vendor_Zend_Locale_Data::getList($locale, 'month');
                 $monthlist2 = IfwPsn_Vendor_Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'format', 'abbreviated'));
                 $monthlist = array_merge($monthlist, $monthlist2);
                 $found = 0;
                 $cnt = 0;
                 foreach ($monthlist as $key => $value) {
                     if (strtoupper($value) == strtoupper($month)) {
                         $found = $key % 12 + 1;
                         break;
                     }
                     ++$cnt;
                 }
                 if ($found == 0) {
                     foreach ($monthlist2 as $key => $value) {
                         if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($month)) {
                             $found = $key + 1;
                             break;
                         }
                         ++$cnt;
                     }
                 }
                 if ($found == 0) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Date_Exception("unknown month name ({$month})", 0, null, $month);
                 }
             }
         }
     }
     $return = $this->_calcdetail($calc, $found, self::MONTH_SHORT, $locale);
     if ($calc != 'cmp') {
         return $this;
     }
     return $return;
 }
示例#2
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Filter_Interface
  *
  * Normalizes the given input
  *
  * @param  string $value Value to normalized
  * @return string|array The normalized value
  */
 public function filter($value)
 {
     if (is_array($value)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Date.php';
         $date = new IfwPsn_Vendor_Zend_Date($value, $this->_options['locale']);
         return $date->toString($this->_options['date_format']);
     } else {
         if ($this->_options['precision'] === 0) {
             return IfwPsn_Vendor_Zend_Locale_Format::toInteger($value, $this->_options);
         } else {
             if ($this->_options['precision'] === null) {
                 return IfwPsn_Vendor_Zend_Locale_Format::toFloat($value, $this->_options);
             }
         }
     }
     return IfwPsn_Vendor_Zend_Locale_Format::toNumber($value, $this->_options);
 }