Exemplo n.º 1
0
 /**
  * Retrieve date format
  *
  * @return string
  */
 protected function _getFormat()
 {
     $format = $this->getColumn()->getFormat();
     if (!$format) {
         if (is_null(self::$_format)) {
             try {
                 $localeCode = $this->_localeResolver->getLocaleCode();
                 $localeData = new \Zend_Locale_Data();
                 switch ($this->getColumn()->getPeriodType()) {
                     case 'month':
                         self::$_format = $localeData->getContent($localeCode, 'dateitem', 'yM');
                         break;
                     case 'year':
                         self::$_format = $localeData->getContent($localeCode, 'dateitem', 'y');
                         break;
                     default:
                         self::$_format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM);
                         break;
                 }
             } catch (\Exception $e) {
             }
         }
         $format = self::$_format;
     }
     return $format;
 }
Exemplo n.º 2
0
 /**
  * Retrieve date format
  *
  * @return string
  */
 protected function _getFormat()
 {
     $format = $this->getColumn()->getFormat();
     if (!$format) {
         if (is_null(self::$_format)) {
             try {
                 $localeCode = Mage::app()->getLocale()->getLocaleCode();
                 $localeData = new Zend_Locale_Data();
                 switch ($this->getColumn()->getPeriodType()) {
                     case 'month':
                         self::$_format = $localeData->getContent($localeCode, 'dateitem', 'yM');
                         break;
                     case 'year':
                         self::$_format = $localeData->getContent($localeCode, 'dateitem', 'y');
                         break;
                     default:
                         self::$_format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
                         break;
                 }
             } catch (Exception $e) {
             }
         }
         $format = self::$_format;
     }
     return $format;
 }
Exemplo n.º 3
0
 /**
  *
  */
 public function getDisplayValue($pa_options = null)
 {
     if (caGetOption('returnAsDecimalWithCurrencySpecifier', $pa_options, false)) {
         return $this->ops_currency_specifier . ' ' . $this->opn_value;
     }
     if (Zend_Registry::isRegistered("Zend_Locale")) {
         $o_locale = Zend_Registry::get('Zend_Locale');
     } else {
         $o_locale = new Zend_Locale('en_US');
     }
     $vs_format = Zend_Locale_Data::getContent($o_locale, 'currencynumber');
     // this returns a string like '50,00 ¤' for locale de_DE
     $vs_decimal_with_placeholder = Zend_Locale_Format::toNumber($this->opn_value, array('locale' => $o_locale, 'number_format' => $vs_format, 'precision' => 2));
     // if the currency placeholder is the first character, for instance in en_US locale ($10), insert a space.
     // we do this because we don't print "$10" (which is expected in the Zend locale rules) but "USD 10" ... and that looks nicer with an additional space.
     // we also replace the weird multibyte nonsense Zend uses as placeholder with something more reasonable so that
     // whatever we output here isn't rejected if thrown into parseValue() again
     if (substr($vs_decimal_with_placeholder, 0, 2) == "¤") {
         // '¤' has length 2
         $vs_decimal_with_placeholder = str_replace("¤", '% ', $vs_decimal_with_placeholder);
     } elseif (substr($vs_decimal_with_placeholder, -2) == "¤") {
         // placeholder at the end
         $vs_decimal_with_placeholder = preg_replace("![^\\d\\,\\.]!", "", $vs_decimal_with_placeholder) . " %";
     }
     // insert currency which is not locale-dependent in our case
     $vs_val = str_replace('%', $this->ops_currency_specifier, $vs_decimal_with_placeholder);
     if (($vs_to_currency = caGetOption('displayCurrencyConversion', $pa_options, false)) && $this->ops_currency_specifier != $vs_to_currency) {
         $vs_val .= " (" . _t("~%1", caConvertCurrencyValue($this->ops_currency_specifier . ' ' . $this->opn_value, $vs_to_currency)) . ")";
     }
     return $vs_val;
 }
Exemplo n.º 4
0
 protected function _toHtml()
 {
     $localeCode = Mage::app()->getLocale()->getLocaleCode();
     // get days names
     $days = Zend_Locale_Data::getList($localeCode, 'days');
     $this->assign('days', array('wide' => Zend_Json::encode(array_values($days['format']['wide'])), 'abbreviated' => Zend_Json::encode(array_values($days['format']['abbreviated']))));
     // get months names
     $months = Zend_Locale_Data::getList($localeCode, 'months');
     $this->assign('months', array('wide' => Zend_Json::encode(array_values($months['format']['wide'])), 'abbreviated' => Zend_Json::encode(array_values($months['format']['abbreviated']))));
     // get "today" and "week" words
     $this->assign('today', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'relative', 0)));
     $this->assign('week', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'field', 'week')));
     // get "am" & "pm" words
     $this->assign('am', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'am')));
     $this->assign('pm', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'pm')));
     // get first day of week and weekend days
     $this->assign('firstDay', (int) Mage::getStoreConfig('general/locale/firstday'));
     $this->assign('weekendDays', Zend_Json::encode((string) Mage::getStoreConfig('general/locale/weekend')));
     // define default format and tooltip format
     $this->assign('defaultFormat', Zend_Json::encode(Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)));
     $this->assign('toolTipFormat', Zend_Json::encode(Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG)));
     // get days and months for en_US locale - calendar will parse exactly in this locale
     $days = Zend_Locale_Data::getList('en_US', 'days');
     $months = Zend_Locale_Data::getList('en_US', 'months');
     $enUS = new stdClass();
     $enUS->m = new stdClass();
     $enUS->m->wide = array_values($months['format']['wide']);
     $enUS->m->abbr = array_values($months['format']['abbreviated']);
     $this->assign('enUS', Zend_Json::encode($enUS));
     return parent::_toHtml();
 }
Exemplo n.º 5
0
 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     $localeCode = $this->_localeResolver->getLocaleCode();
     // get days names
     $days = \Zend_Locale_Data::getList($localeCode, 'days');
     $this->assign('days', array('wide' => $this->encoder->encode(array_values($days['format']['wide'])), 'abbreviated' => $this->encoder->encode(array_values($days['format']['abbreviated']))));
     // get months names
     $months = \Zend_Locale_Data::getList($localeCode, 'months');
     $this->assign('months', array('wide' => $this->encoder->encode(array_values($months['format']['wide'])), 'abbreviated' => $this->encoder->encode(array_values($months['format']['abbreviated']))));
     // get "today" and "week" words
     $this->assign('today', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'relative', 0)));
     $this->assign('week', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'field', 'week')));
     // get "am" & "pm" words
     $this->assign('am', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'am')));
     $this->assign('pm', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'pm')));
     // get first day of week and weekend days
     $this->assign('firstDay', (int) $this->_scopeConfig->getValue('general/locale/firstday', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
     $this->assign('weekendDays', $this->encoder->encode((string) $this->_scopeConfig->getValue('general/locale/weekend', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)));
     // define default format and tooltip format
     $this->assign('defaultFormat', $this->encoder->encode($this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_MEDIUM)));
     $this->assign('toolTipFormat', $this->encoder->encode($this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_LONG)));
     // get days and months for en_US locale - calendar will parse exactly in this locale
     $days = \Zend_Locale_Data::getList('en_US', 'days');
     $months = \Zend_Locale_Data::getList('en_US', 'months');
     $enUS = new \stdClass();
     $enUS->m = new \stdClass();
     $enUS->m->wide = array_values($months['format']['wide']);
     $enUS->m->abbr = array_values($months['format']['abbreviated']);
     $this->assign('enUS', $this->encoder->encode($enUS));
     return parent::_toHtml();
 }
Exemplo n.º 6
0
 /**
  *
  */
 public function getDisplayValue($pa_options = null)
 {
     if (caGetOption('returnAsDecimalWithCurrencySpecifier', $pa_options, false)) {
         return $this->ops_currency_specifier . ' ' . $this->opn_value;
     }
     if (Zend_Registry::isRegistered("Zend_Locale")) {
         $o_locale = Zend_Registry::get('Zend_Locale');
     } else {
         $o_locale = new Zend_Locale('en_US');
     }
     $vs_format = Zend_Locale_Data::getContent($o_locale, 'currencynumber');
     // this returns a string like '50,00 ¤' for locale de_DE
     $vs_decimal_with_placeholder = Zend_Locale_Format::toNumber($this->opn_value, array('locale' => $locale, 'number_format' => $vs_format, 'precision' => 2));
     // if the currency placeholder is the first character, for instance in en_US locale ($10), insert a space.
     // this has to be done because we don't print "$10" (which is expected in the locale rules) but "USD 10" ... and that looks nicer with an additional space.
     if (substr($vs_decimal_with_placeholder, 0, 2) == '¤') {
         // for whatever reason '¤' has length 2
         $vs_decimal_with_placeholder = str_replace('¤', '¤ ', $vs_decimal_with_placeholder);
     }
     // insert currency which is not locale-dependent in our case
     $vs_val = str_replace('¤', $this->ops_currency_specifier, $vs_decimal_with_placeholder);
     if (($vs_to_currency = caGetOption('displayCurrencyConversion', $pa_options, false)) && $this->ops_currency_specifier != $vs_to_currency) {
         $vs_val .= " (" . _t("~%1", caConvertCurrencyValue($this->ops_currency_specifier . ' ' . $this->opn_value, $vs_to_currency)) . ")";
     }
     return $vs_val;
 }
Exemplo n.º 7
0
 /**
  * Functions returns array with price formating info for js function
  * formatCurrency in js/varien/js.js
  *
  * @return array
  */
 public function getJsPriceFormat()
 {
     $format = Zend_Locale_Data::getContent($this->getLocaleCode(), 'currencynumber');
     $symbols = Zend_Locale_Data::getList($this->getLocaleCode(), 'symbols');
     $pos = strpos($format, ';');
     if ($pos !== false) {
         $format = substr($format, 0, $pos);
     }
     $format = preg_replace("/[^0\\#\\.,]/", "", $format);
     $totalPrecision = 0;
     $decimalPoint = strpos($format, '.');
     if ($decimalPoint !== false) {
         $totalPrecision = strlen($format) - (strrpos($format, '.') + 1);
     } else {
         $decimalPoint = strlen($format);
     }
     //hook for changing precision
     $totalPrecision = VF_Currency_Model_Directory_Currency::PRECISION;
     $requiredPrecision = $totalPrecision;
     $temp = substr($format, $decimalPoint);
     $pos = strpos($temp, '#');
     if ($pos !== false) {
         $requiredPrecision = strlen($temp) - $pos - $totalPrecision;
     }
     $group = 0;
     if (strrpos($format, ',') !== false) {
         $group = $decimalPoint - strrpos($format, ',') - 1;
     } else {
         $group = strrpos($format, '.');
     }
     $integerRequired = strpos($format, '.') - strpos($format, '0');
     $result = array('pattern' => Mage::app()->getStore()->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $symbols['decimal'], 'groupSymbol' => $symbols['group'], 'groupLength' => $group, 'integerRequired' => $integerRequired);
     return $result;
 }
Exemplo n.º 8
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view;
     $locale = Zend_Registry::get('Zend_Locale');
     $view->locale = key($locale->getDefault());
     $view->date_format = Zend_Locale_Data::getContent($view->locale, 'date');
 }
Exemplo n.º 9
0
Arquivo: Date.php Projeto: abdala/la
 /**
  * Class constructor
  *
  * @param array|Zend_Config $options (Optional)
  */
 public function __construct($options = null)
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     }
     if (null === $options) {
         $locale = Zend_Registry::get('Zend_Locale')->toString();
         $dateFormat = Zend_Locale_Data::getContent($locale, 'date');
         $options = array('locale' => $locale, 'date_format' => $dateFormat);
     }
     $this->setOptions($options);
 }
Exemplo n.º 10
0
 public function addAction()
 {
     $form = new Zetta_Form(Zend_Registry::get('config')->Cron->form->task);
     /* заполняем выпадающие списки данными */
     $minute = $form->getElement('minute');
     for ($i = -1; $i <= 59; $i++) {
         $i == -1 ? $minute->addMultiOption('*', '*') : $minute->addMultiOption($i, $i);
     }
     $hour = $form->getElement('hour');
     for ($i = -1; $i <= 23; $i++) {
         $i == -1 ? $hour->addMultiOption('*', '*') : $hour->addMultiOption($i, sprintf('%02d', $i));
     }
     $day = $form->getElement('day');
     for ($i = 0; $i <= 31; $i++) {
         $i == 0 ? $day->addMultiOption('*', '*') : $day->addMultiOption($i, sprintf('%02d', $i));
     }
     $month = $form->getElement('month');
     for ($i = 0; $i <= 12; $i++) {
         if ($i == 0) {
             $month->addMultiOption('*', '*');
         } else {
             $month_str = Zend_Locale_Data::getContent(new Zend_Locale(), 'month', array('gregorian', 'stand-alone', 'wide', intval($i)));
             $month->addMultiOption($i, $month_str);
         }
     }
     $week = $form->getElement('week_day');
     $array_weekDay = array('', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
     for ($i = 0; $i <= 7; $i++) {
         if ($i == 0) {
             $week->addMultiOption('*', '*');
         } else {
             $week_str = Zend_Locale_Data::getContent(new Zend_Locale(), 'day', array('gregorian', 'format', 'wide', $array_weekDay[$i]));
             $week->addMultiOption($i, $week_str);
         }
     }
     if ($cron_id = $this->getParam('cron_id')) {
         $this->view->cron_id = $cron_id;
         $editData = $this->_model->fetchRow($this->_model->select()->where('cron_id = ?', $cron_id))->toArray();
         $form->setDefaults($editData);
     }
     if (!sizeof($_POST) || !$form->isValid($_POST)) {
         $this->view->form = $form;
     } else {
         $arrayData = array('minute' => $form->getValue('minute'), 'hour' => $form->getValue('hour'), 'day' => $form->getValue('day'), 'month' => $form->getValue('month'), 'week_day' => $form->getValue('week_day'), 'task' => $form->getValue('task'), 'active' => (bool) $form->getValue('active') == true ? '1' : new Zend_Db_Expr('NULL'));
         if ($cron_id) {
             $this->_model->update($arrayData, $this->_model->getAdapter()->quoteInto('cron_id = ?', $cron_id));
         } else {
             $this->_model->insert($arrayData);
         }
         $this->renderScript('admin/addComplete.ajax.phtml');
     }
 }
Exemplo n.º 11
0
 public function render(Zend_View_Interface $view = null)
 {
     if ($this->_fieldMeta instanceof Fields_Model_Meta && !empty($this->_fieldMeta->config['unit'])) {
         //$currency = new Zend_Currency($this->_fieldMeta->config['unit']);
         $localeObject = Zend_Registry::get('Locale');
         $currencyCode = $this->_fieldMeta->config['unit'];
         $currencyName = Zend_Locale_Data::getContent($localeObject, 'nametocurrency', $currencyCode);
         $this->loadDefaultDecorators();
         $this->getDecorator('Label')->setOption('optionalSuffix', ' - ' . $currencyCode)->setOption('requiredSuffix', ' - ' . $currencyCode);
         if ($currencyName && !$this->getDescription()) {
             $this->setDescription($currencyName);
             $this->getDecorator('Description')->setOption('placement', 'APPEND');
         }
     }
     return parent::render($view);
 }
Exemplo n.º 12
0
 /**
  * Returns the actual or details of available currency symbol choice,
  *
  * @param  string             $currency (Optional) Currency name
  * @param  string|Zend_Locale $locale   (Optional) Locale to display informations
  * @return string
  */
 public function getSymbolChoice($currency = null, $locale = null)
 {
     if ($currency === null and $locale === null) {
         return $this->_options['symbol_choice'];
     }
     $params = self::_checkParams($currency, $locale);
     //Get the symbol choice
     $symbolChoice = Zend_Locale_Data::getContent($params['locale'], 'currencysymbolchoice', $params['currency']);
     if (empty($symbolChoice) === true) {
         $symbolChoice = Zend_Locale_Data::getContent($params['locale'], 'currencysymbolchoice', $params['name']);
     }
     if (empty($symbolChoice) === true) {
         return null;
     }
     return $symbolChoice;
 }
Exemplo n.º 13
0
 public function __construct()
 {
     parent::__construct();
     $this->i18n_dir = dirname(dirname(__FILE__)) . "/i18n";
     $current_locale = P4A::singleton()->i18n->getLocale();
     $languages = array();
     foreach (scandir($this->i18n_dir) as $file) {
         if (substr($file, -4) == ".php") {
             $locale = substr($file, 0, -4);
             list($language_code, $region_code) = explode("_", $locale);
             $language_name = Zend_Locale_Data::getContent($current_locale, 'language', $language_code);
             $region_name = Zend_Locale_Data::getContent($current_locale, 'country', $region_code);
             $languages[] = array("locale" => $locale, "description" => "{$language_name} ({$region_name})");
         }
     }
     $this->build("P4A_Array_Source", "languages")->setPk("locale")->load($languages);
     $this->build("P4A_Field", "choose_language")->setType("radio")->setValue($current_locale)->setSource($this->languages);
     $this->choose_language->label->setWidth(120);
     $this->build("P4A_Button", "apply")->implement("onclick", $this, "apply");
     $this->frame->anchor($this->choose_language)->newRow()->anchorCenter($this->apply);
 }
Exemplo n.º 14
0
 /**
  * Parses a Zend_Currency & Zend_Locale into a NostoCurrency object.
  *
  * REQUIRES Zend Framework (version 1) to be available.
  *
  * @param string $currencyCode the 3-letter ISO 4217 currency code.
  * @param Zend_Currency $zendCurrency the zend currency object.
  * @return NostoCurrency the parsed nosto currency object.
  *
  * @throws NostoInvalidArgumentException
  */
 public function parseZendCurrencyFormat($currencyCode, Zend_Currency $zendCurrency)
 {
     try {
         $format = Zend_Locale_Data::getContent($zendCurrency->getLocale(), 'currencynumber');
         $symbols = Zend_Locale_Data::getList($zendCurrency->getLocale(), 'symbols');
         // Remove extra part, e.g. "¤ #,##0.00; (¤ #,##0.00)" => "¤ #,##0.00".
         if (($pos = strpos($format, ';')) !== false) {
             $format = substr($format, 0, $pos);
         }
         // Check if the currency symbol is before or after the amount.
         $symbolPosition = strpos(trim($format), '¤') === 0 ? NostoCurrencySymbol::SYMBOL_POS_LEFT : NostoCurrencySymbol::SYMBOL_POS_RIGHT;
         // Remove all other characters than "0", "#", "." and ",",
         $format = preg_replace('/[^0\\#\\.,]/', '', $format);
         // Calculate the decimal precision.
         $precision = 0;
         if (($decimalPos = strpos($format, '.')) !== false) {
             $precision = strlen($format) - (strrpos($format, '.') + 1);
         } else {
             $decimalPos = strlen($format);
         }
         $decimalFormat = substr($format, $decimalPos);
         if (($pos = strpos($decimalFormat, '#')) !== false) {
             $precision = strlen($decimalFormat) - $pos - $precision;
         }
         // Calculate the group length.
         if (strrpos($format, ',') !== false) {
             $groupLength = $decimalPos - strrpos($format, ',') - 1;
         } else {
             $groupLength = strrpos($format, '.');
         }
         // If the symbol is missing for the current locale, use the ISO code.
         $currencySymbol = $zendCurrency->getSymbol();
         if (is_null($currencySymbol)) {
             $currencySymbol = $currencyCode;
         }
         return new NostoCurrency(new NostoCurrencyCode($currencyCode), new NostoCurrencySymbol($currencySymbol, $symbolPosition), new NostoCurrencyFormat($symbols['group'], $groupLength, $symbols['decimal'], $precision));
     } catch (Zend_Exception $e) {
         throw new NostoInvalidArgumentException($e);
     }
 }
Exemplo n.º 15
0
 /**
  * Functions returns array with price formatting info for js function
  * formatCurrency in js/varien/js.js
  *
  * @return array
  */
 public function getJsPriceFormat()
 {
     $format = Zend_Locale_Data::getContent($this->getLocaleCode(), 'currencynumber');
     $symbols = Zend_Locale_Data::getList($this->getLocaleCode(), 'symbols');
     $pos = strpos($format, ';');
     if ($pos !== false) {
         $format = substr($format, 0, $pos);
     }
     $format = preg_replace("/[^0\\#\\.,]/", "", $format);
     $totalPrecision = 0;
     $decimalPoint = strpos($format, '.');
     if ($decimalPoint !== false) {
         $totalPrecision = strlen($format) - (strrpos($format, '.') + 1);
     } else {
         $decimalPoint = strlen($format);
     }
     $requiredPrecision = $totalPrecision;
     $t = substr($format, $decimalPoint);
     $pos = strpos($t, '#');
     if ($pos !== false) {
         $requiredPrecision = strlen($t) - $pos - $totalPrecision;
     }
     $group = 0;
     if (strrpos($format, ',') !== false) {
         $group = $decimalPoint - strrpos($format, ',') - 1;
     } else {
         $group = strrpos($format, '.');
     }
     $integerRequired = strpos($format, '.') - strpos($format, '0');
     //get the store id so you an correctly reference the global variable
     $store_id = Mage::app()->getStore()->getId();
     //JASE get precision from custom variable that can be set at store level
     $getPrecision = Mage::getModel('core/variable')->setStoreId($store_id)->loadByCode('decimalPrecision')->getData('store_plain_value');
     //if set use it, otherwise default to two decimals
     $totalPrecision = is_numeric($getPrecision) ? $getPrecision : $totalPrecision;
     $requiredPrecision = is_numeric($getPrecision) ? $getPrecision : $requiredPrecision;
     $result = array('pattern' => Mage::app()->getStore()->getCurrentCurrency()->getOutputFormat(), 'precision' => 0, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $symbols['decimal'], 'groupSymbol' => $symbols['group'], 'groupLength' => $group, 'integerRequired' => $integerRequired);
     return $result;
 }
Exemplo n.º 16
0
 /**
  * Returns a localized information string, supported are several types of informations.
  * For detailed information about the types look into the documentation
  *
  * @param  string             $value  Name to get detailed information about
  * @param  string             $path   (Optional) Type of information to return
  * @param  string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
  * @return string|false The wished information in the given language
  */
 public static function getTranslation($value = null, $path = null, $locale = null)
 {
     require_once 'Zend/Locale/Data.php';
     $locale = self::findLocale($locale);
     $result = Zend_Locale_Data::getContent($locale, $path, $value);
     if (empty($result) === true) {
         return false;
     }
     return $result;
 }
Exemplo n.º 17
0
 /**
  * Returns the default datetime format for $locale.
  *
  * @param  string|Zend_Locale  $locale  OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
  * @return string  format
  */
 public static function getDateTimeFormat($locale = null)
 {
     $format = Zend_Locale_Data::getContent($locale, 'datetime');
     if (empty($format)) {
         // require_once 'Zend/Locale/Exception.php';
         throw new Zend_Locale_Exception("failed to receive data from locale {$locale}");
     }
     return $format;
 }
Exemplo n.º 18
0
 /**
  * Returns a list of regions where this currency is or was known
  *
  * @param  string $currency OPTIONAL Currency's short name
  * @throws Zend_Currency_Exception When no currency was defined
  * @return array List of regions
  */
 public function getRegionList($currency = null)
 {
     if ($currency === null) {
         $currency = $this->_options['currency'];
     }
     if (empty($currency) === true) {
         require_once 'Zend/Currency/Exception.php';
         throw new Zend_Currency_Exception('No currency defined');
     }
     $data = Zend_Locale_Data::getContent('', 'regiontocurrency', $currency);
     $result = explode(' ', $data);
     return $result;
 }
Exemplo n.º 19
0
 /**
  * Returns the ISO Token for all localized constants
  *
  * @param string $token Token to normalize
  * @param string $locale Locale to search
  * @return string
  */
 protected static function _getLocalizedToken($token, $locale)
 {
     switch ($token) {
         case self::ISO_8601:
             return "yyyy-MM-ddThh:mm:ss";
             break;
         case self::RFC_2822:
             return "EEE, dd MMM yyyy HH:mm:ss";
             break;
         case self::DATES:
             return Zend_Locale_Data::getContent($locale, 'date');
             break;
         case self::DATE_FULL:
             return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full'));
             break;
         case self::DATE_LONG:
             return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long'));
             break;
         case self::DATE_MEDIUM:
             return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium'));
             break;
         case self::DATE_SHORT:
             return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short'));
             break;
         case self::TIMES:
             return Zend_Locale_Data::getContent($locale, 'time');
             break;
         case self::TIME_FULL:
             return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'full'));
             break;
         case self::TIME_LONG:
             return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'long'));
             break;
         case self::TIME_MEDIUM:
             return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'medium'));
             break;
         case self::TIME_SHORT:
             return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'short'));
             break;
         case self::DATETIME:
             return Zend_Locale_Data::getContent($locale, 'datetime');
             break;
         case self::DATETIME_FULL:
             return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full'));
             break;
         case self::DATETIME_LONG:
             return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long'));
             break;
         case self::DATETIME_MEDIUM:
             return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium'));
             break;
         case self::DATETIME_SHORT:
             return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short'));
             break;
         case self::ATOM:
         case self::RFC_3339:
         case self::W3C:
             return "yyyy-MM-DD HH:mm:ss";
             break;
         case self::COOKIE:
         case self::RFC_850:
             return "EEEE, dd-MM-yyyy HH:mm:ss";
             break;
         case self::RFC_822:
         case self::RFC_1036:
         case self::RFC_1123:
         case self::RSS:
             return "EEE, dd MM yyyy HH:mm:ss";
             break;
     }
     return $token;
 }
Exemplo n.º 20
0
 /**
  * Calculates the date or object
  *
  * @param  string                          $calc    Calculation to make, one of: 'add'|'sub'|'cmp'|'copy'|'set'
  * @param  string|integer|array|Zend_Date  $date    Date or datepart to calculate with
  * @param  string                          $part    Part of the date to calculate, if null the timestamp is used
  * @param  string|Zend_Locale              $locale  Locale for parsing input
  * @return integer|string|Zend_Date        new timestamp
  * @throws Zend_Date_Exception
  */
 private function _calculate($calc, $date, $part, $locale)
 {
     if (is_null($date) === true) {
         require_once 'Zend/Date/Exception.php';
         throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');
     }
     if ($part !== null and Zend_Locale::isLocale($part, null, false)) {
         $locale = $part;
         $part = null;
     }
     if ($locale === null) {
         $locale = $this->getLocale();
     }
     $locale = (string) $locale;
     // Create date parts
     $year = $this->get(self::YEAR);
     $month = $this->get(self::MONTH_SHORT);
     $day = $this->get(self::DAY_SHORT);
     $hour = $this->get(self::HOUR_SHORT);
     $minute = $this->get(self::MINUTE_SHORT);
     $second = $this->get(self::SECOND_SHORT);
     // If object extract value
     if ($date instanceof Zend_Date) {
         $date = $date->get($part, $locale);
     }
     if (is_array($date) === true) {
         if (empty($part) === false) {
             switch ($part) {
                 // Fall through
                 case self::DAY:
                 case self::DAY_SHORT:
                     if (isset($date['day']) === true) {
                         $date = $date['day'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case self::WEEKDAY_SHORT:
                 case self::WEEKDAY:
                 case self::WEEKDAY_8601:
                 case self::WEEKDAY_DIGIT:
                 case self::WEEKDAY_NARROW:
                 case self::WEEKDAY_NAME:
                     if (isset($date['weekday']) === true) {
                         $date = $date['weekday'];
                         $part = self::WEEKDAY_DIGIT;
                     }
                     break;
                 case self::DAY_OF_YEAR:
                     if (isset($date['day_of_year']) === true) {
                         $date = $date['day_of_year'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case self::MONTH:
                 case self::MONTH_SHORT:
                 case self::MONTH_NAME:
                 case self::MONTH_NAME_SHORT:
                 case self::MONTH_NAME_NARROW:
                     if (isset($date['month']) === true) {
                         $date = $date['month'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case self::YEAR:
                 case self::YEAR_SHORT:
                 case self::YEAR_8601:
                 case self::YEAR_SHORT_8601:
                     if (isset($date['year']) === true) {
                         $date = $date['year'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case self::HOUR:
                 case self::HOUR_AM:
                 case self::HOUR_SHORT:
                 case self::HOUR_SHORT_AM:
                     if (isset($date['hour']) === true) {
                         $date = $date['hour'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case self::MINUTE:
                 case self::MINUTE_SHORT:
                     if (isset($date['minute']) === true) {
                         $date = $date['minute'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case self::SECOND:
                 case self::SECOND_SHORT:
                     if (isset($date['second']) === true) {
                         $date = $date['second'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case self::TIMEZONE:
                 case self::TIMEZONE_NAME:
                     if (isset($date['timezone']) === true) {
                         $date = $date['timezone'];
                     }
                     break;
                 case self::TIMESTAMP:
                     if (isset($date['timestamp']) === true) {
                         $date = $date['timestamp'];
                     }
                     break;
                 case self::WEEK:
                     if (isset($date['week']) === true) {
                         $date = $date['week'];
                     }
                     break;
                 case self::TIMEZONE_SECS:
                     if (isset($date['gmtsecs']) === true) {
                         $date = $date['gmtsecs'];
                     }
                     break;
                 default:
                     require_once 'Zend/Date/Exception.php';
                     throw new Zend_Date_Exception("datepart for part ({$part}) not found in array");
                     break;
             }
         } else {
             $hours = 0;
             if (isset($date['hour']) === true) {
                 $hours = $date['hour'];
             }
             $minutes = 0;
             if (isset($date['minute']) === true) {
                 $minutes = $date['minute'];
             }
             $seconds = 0;
             if (isset($date['second']) === true) {
                 $seconds = $date['second'];
             }
             $months = 0;
             if (isset($date['month']) === true) {
                 $months = $date['month'];
             }
             $days = 0;
             if (isset($date['day']) === true) {
                 $days = $date['day'];
             }
             $years = 0;
             if (isset($date['year']) === true) {
                 $years = $date['year'];
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, $months, $days, $years, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), $hour);
         }
     }
     // $date as object, part of foreign date as own date
     switch ($part) {
         // day formats
         case self::DAY:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true), $this->mktime(0, 0, 0, 1, 1 + intval($day), 1970, true), $hour);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", $date);
             break;
         case self::WEEKDAY_SHORT:
             $daylist = Zend_Locale_Data::getList($locale, 'day');
             $weekday = (int) $this->get(self::WEEKDAY_DIGIT, $locale);
             $cnt = 0;
             foreach ($daylist as $key => $value) {
                 if (strtoupper(iconv_substr($value, 0, 3, 'UTF-8')) == strtoupper($date)) {
                     $found = $cnt;
                     break;
                 }
                 ++$cnt;
             }
             // Weekday found
             if ($cnt < 7) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
             }
             // Weekday not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case self::DAY_SHORT:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true), $this->mktime(0, 0, 0, 1, 1 + intval($day), 1970, true), $hour);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", $date);
             break;
         case self::WEEKDAY:
             $daylist = Zend_Locale_Data::getList($locale, 'day');
             $weekday = (int) $this->get(self::WEEKDAY_DIGIT, $locale);
             $cnt = 0;
             foreach ($daylist as $key => $value) {
                 if (strtoupper($value) == strtoupper($date)) {
                     $found = $cnt;
                     break;
                 }
                 ++$cnt;
             }
             // Weekday found
             if ($cnt < 7) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
             }
             // Weekday not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case self::WEEKDAY_8601:
             $weekday = (int) $this->get(self::WEEKDAY_8601, $locale);
             if (intval($date) > 0 and intval($date) < 8) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
             }
             // Weekday not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case self::DAY_SUFFIX:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('day suffix not supported', $date);
             break;
         case self::WEEKDAY_DIGIT:
             $weekday = (int) $this->get(self::WEEKDAY_DIGIT, $locale);
             if (is_numeric($date) and intval($date) >= 0 and intval($date) < 7) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $date, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
             }
             // Weekday not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case self::DAY_OF_YEAR:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $date, 1970, true), $this->mktime(0, 0, 0, $month, 1 + $day, 1970, true), $hour);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", $date);
             break;
         case self::WEEKDAY_NARROW:
             $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated'));
             $weekday = (int) $this->get(self::WEEKDAY_DIGIT, $locale);
             $cnt = 0;
             foreach ($daylist as $key => $value) {
                 if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($date)) {
                     $found = $cnt;
                     break;
                 }
                 ++$cnt;
             }
             // Weekday found
             if ($cnt < 7) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
             }
             // Weekday not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case self::WEEKDAY_NAME:
             $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated'));
             $weekday = (int) $this->get(self::WEEKDAY_DIGIT, $locale);
             $cnt = 0;
             foreach ($daylist as $key => $value) {
                 if (strtoupper($value) == strtoupper($date)) {
                     $found = $cnt;
                     break;
                 }
                 ++$cnt;
             }
             // Weekday found
             if ($cnt < 7) {
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true), $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
             }
             // Weekday not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
             // week formats
         // week formats
         case self::WEEK:
             if (is_numeric($date)) {
                 $week = (int) $this->get(self::WEEK, $locale);
                 return $this->_assign($calc, parent::mktime(0, 0, 0, 1, 1 + $date * 7, 1970, true), parent::mktime(0, 0, 0, 1, 1 + $week * 7, 1970, true), $hour);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, week expected", $date);
             break;
             // month formats
         // month formats
         case self::MONTH_NAME:
             $monthlist = Zend_Locale_Data::getList($locale, 'month');
             $cnt = 0;
             foreach ($monthlist as $key => $value) {
                 if (strtoupper($value) == strtoupper($date)) {
                     $found = $key;
                     break;
                 }
                 ++$cnt;
             }
             $date = array_search($date, $monthlist);
             // Monthname found
             if ($cnt < 12) {
                 $fixday = 0;
                 if ($calc == 'add') {
                     $date += $found;
                     $calc = 'set';
                     if (self::$_options['extend_month'] == false) {
                         $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                         if ($parts['mday'] != $day) {
                             $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                         }
                     }
                 } else {
                     if ($calc == 'sub') {
                         $date = $month - $found;
                         $calc = 'set';
                         if (self::$_options['extend_month'] == false) {
                             $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                             if ($parts['mday'] != $day) {
                                 $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                             }
                         }
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
             }
             // Monthname not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case self::MONTH:
             if (is_numeric($date)) {
                 $fixday = 0;
                 if ($calc == 'add') {
                     $date += $month;
                     $calc = 'set';
                     if (self::$_options['extend_month'] == false) {
                         $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                         if ($parts['mday'] != $day) {
                             $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                         }
                     }
                 } else {
                     if ($calc == 'sub') {
                         $date = $month - $date;
                         $calc = 'set';
                         if (self::$_options['extend_month'] == false) {
                             $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                             if ($parts['mday'] != $day) {
                                 $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                             }
                         }
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case self::MONTH_NAME_SHORT:
             $monthlist = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'format', 'abbreviated'));
             $cnt = 0;
             foreach ($monthlist as $key => $value) {
                 if (strtoupper($value) == strtoupper($date)) {
                     $found = $key;
                     break;
                 }
                 ++$cnt;
             }
             $date = array_search($date, $monthlist);
             // Monthname found
             if ($cnt < 12) {
                 $fixday = 0;
                 if ($calc == 'add') {
                     $date += $found;
                     $calc = 'set';
                     if (self::$_options['extend_month'] === false) {
                         $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                         if ($parts['mday'] != $day) {
                             $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                         }
                     }
                 } else {
                     if ($calc == 'sub') {
                         $date = $month - $found;
                         $calc = 'set';
                         if (self::$_options['extend_month'] === false) {
                             $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                             if ($parts['mday'] != $day) {
                                 $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                             }
                         }
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
             }
             // Monthname not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case self::MONTH_SHORT:
             if (is_numeric($date) === true) {
                 $fixday = 0;
                 if ($calc === 'add') {
                     $date += $month;
                     $calc = 'set';
                     if (self::$_options['extend_month'] === false) {
                         $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                         if ($parts['mday'] != $day) {
                             $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                         }
                     }
                 } else {
                     if ($calc === 'sub') {
                         $date = $month - $date;
                         $calc = 'set';
                         if (self::$_options['extend_month'] === false) {
                             $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                             if ($parts['mday'] != $day) {
                                 $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                             }
                         }
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case self::MONTH_DAYS:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('month days not supported', $date);
             break;
         case self::MONTH_NAME_NARROW:
             $monthlist = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'stand-alone', 'narrow'));
             $cnt = 0;
             foreach ($monthlist as $key => $value) {
                 if (strtoupper($value) === strtoupper($date)) {
                     $found = $key;
                     break;
                 }
                 ++$cnt;
             }
             $date = array_search($date, $monthlist);
             // Monthname found
             if ($cnt < 12) {
                 $fixday = 0;
                 if ($calc === 'add') {
                     $date += $found;
                     $calc = 'set';
                     if (self::$_options['extend_month'] === false) {
                         $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                         if ($parts['mday'] != $day) {
                             $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                         }
                     }
                 } else {
                     if ($calc === 'sub') {
                         $date = $month - $found;
                         $calc = 'set';
                         if (self::$_options['extend_month'] === false) {
                             $parts = $this->getDateParts($this->mktime(0, 0, 0, $date, $day, $year, false));
                             if ($parts['mday'] != $day) {
                                 $fixday = $parts['mday'] < $day ? -$parts['mday'] : $parts['mday'] - $day;
                             }
                         }
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
             }
             // Monthname not found
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
             // year formats
         // year formats
         case self::LEAPYEAR:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('leap year not supported', $date);
             break;
         case self::YEAR_8601:
             if (is_numeric($date)) {
                 if ($calc === 'add') {
                     $date += $year;
                     $calc = 'set';
                 } else {
                     if ($calc === 'sub') {
                         $date = $year - $date;
                         $calc = 'set';
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, intval($date), true), $this->mktime(0, 0, 0, $month, $day, $year, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
         case self::YEAR:
             if (is_numeric($date)) {
                 if ($calc === 'add') {
                     $date += $year;
                     $calc = 'set';
                 } else {
                     if ($calc === 'sub') {
                         $date = $year - $date;
                         $calc = 'set';
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, intval($date), true), $this->mktime(0, 0, 0, $month, $day, $year, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
         case self::YEAR_SHORT:
             if (is_numeric($date)) {
                 $date = intval($date);
                 if ($calc == 'set' || $calc == 'cmp') {
                     $date = self::getFullYear($date);
                 }
                 if ($calc === 'add') {
                     $date += $year;
                     $calc = 'set';
                 } else {
                     if ($calc === 'sub') {
                         $date = $year - $date;
                         $calc = 'set';
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, $date, true), $this->mktime(0, 0, 0, $month, $day, $year, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
         case self::YEAR_SHORT_8601:
             if (is_numeric($date)) {
                 $date = intval($date);
                 if ($calc === 'set' || $calc === 'cmp') {
                     $date = self::getFullYear($date);
                 }
                 if ($calc === 'add') {
                     $date += $year;
                     $calc = 'set';
                 } else {
                     if ($calc === 'sub') {
                         $date = $year - $date;
                         $calc = 'set';
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, $date, true), $this->mktime(0, 0, 0, $month, $day, $year, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
             // time formats
         // time formats
         case self::MERIDIEM:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('meridiem not supported', $date);
             break;
         case self::SWATCH:
             if (is_numeric($date)) {
                 $rest = intval($date);
                 $hours = floor($rest * 24 / 1000);
                 $rest = $rest - $hours * 1000 / 24;
                 $minutes = floor($rest * 1440 / 1000);
                 $rest = $rest - $minutes * 1000 / 1440;
                 $seconds = floor($rest * 86400 / 1000);
                 return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1, 1, 1970, true), $this->mktime($hour, $minute, $second, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, swatchstamp expected", $date);
             break;
         case self::HOUR_SHORT_AM:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case self::HOUR_SHORT:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case self::HOUR_AM:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case self::HOUR:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true), $this->mktime($hour, 0, 0, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case self::MINUTE:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(0, intval($date), 0, 1, 1, 1970, true), $this->mktime(0, $minute, 0, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, minute expected", $date);
             break;
         case self::SECOND:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(0, 0, intval($date), 1, 1, 1970, true), $this->mktime(0, 0, $second, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, second expected", $date);
             break;
         case self::MILLISECOND:
             if (is_numeric($date)) {
                 switch ($calc) {
                     case 'set':
                         return $this->setMillisecond($date);
                         break;
                     case 'add':
                         return $this->addMillisecond($date);
                         break;
                     case 'sub':
                         return $this->subMillisecond($date);
                         break;
                 }
                 return $this->compareMillisecond($date);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, milliseconds expected", $date);
             break;
         case self::MINUTE_SHORT:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(0, intval($date), 0, 1, 1, 1970, true), $this->mktime(0, $minute, 0, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, minute expected", $date);
             break;
         case self::SECOND_SHORT:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $this->mktime(0, 0, intval($date), 1, 1, 1970, true), $this->mktime(0, 0, $second, 1, 1, 1970, true), false);
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, second expected", $date);
             break;
             // timezone formats
             // break intentionally omitted
         // timezone formats
         // break intentionally omitted
         case self::TIMEZONE_NAME:
         case self::TIMEZONE:
         case self::TIMEZONE_SECS:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('timezone not supported', $date);
             break;
         case self::DAYLIGHT:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('daylight not supported', $date);
             break;
         case self::GMT_DIFF:
         case self::GMT_DIFF_SEP:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('gmtdiff not supported', $date);
             break;
             // date strings
         // date strings
         case self::ISO_8601:
             // (-)YYYY-MM-dd
             preg_match('/^(-{0,1}\\d{4})-(\\d{2})-(\\d{2})/', $date, $datematch);
             // (-)YY-MM-dd
             if (empty($datematch)) {
                 preg_match('/^(-{0,1}\\d{2})-(\\d{2})-(\\d{2})/', $date, $datematch);
             }
             // (-)YYYYMMdd
             if (empty($datematch)) {
                 preg_match('/^(-{0,1}\\d{4})(\\d{2})(\\d{2})/', $date, $datematch);
             }
             // (-)YYMMdd
             if (empty($datematch)) {
                 preg_match('/^(-{0,1}\\d{2})(\\d{2})(\\d{2})/', $date, $datematch);
             }
             $tmpdate = $date;
             if (!empty($datematch)) {
                 $dateMatchCharCount = iconv_strlen($datematch[0], 'UTF-8');
                 $tmpdate = iconv_substr($date, $dateMatchCharCount, iconv_strlen($date, 'UTF-8') - $dateMatchCharCount, 'UTF-8');
             }
             // (T)hh:mm:ss
             preg_match('/[T,\\s]{0,1}(\\d{2}):(\\d{2}):(\\d{2})/', $tmpdate, $timematch);
             if (empty($timematch)) {
                 preg_match('/[T,\\s]{0,1}(\\d{2})(\\d{2})(\\d{2})/', $tmpdate, $timematch);
             }
             if (empty($datematch) and empty($timematch)) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("unsupported ISO8601 format ({$date})", $date);
             }
             if (!empty($timematch)) {
                 $timeMatchCharCount = iconv_strlen($timematch[0], 'UTF-8');
                 $tmpdate = iconv_substr($tmpdate, $timeMatchCharCount, iconv_strlen($tmpdate, 'UTF-8') - $timeMatchCharCount, 'UTF-8');
             }
             if (empty($datematch)) {
                 $datematch[1] = 1970;
                 $datematch[2] = 1;
                 $datematch[3] = 1;
             } else {
                 if (iconv_strlen($datematch[1], 'UTF-8') == 2) {
                     $datematch[1] = self::getFullYear($datematch[1]);
                 }
             }
             if (empty($timematch)) {
                 $timematch[1] = 0;
                 $timematch[2] = 0;
                 $timematch[3] = 0;
             }
             if ($calc == 'set' || $calc == 'cmp') {
                 --$datematch[2];
                 --$month;
                 --$datematch[3];
                 --$day;
                 $datematch[1] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($timematch[1], $timematch[2], $timematch[3], 1 + $datematch[2], 1 + $datematch[3], 1970 + $datematch[1], false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false);
             break;
         case self::RFC_2822:
             $result = preg_match('/^\\w{3},\\s(\\d{1,2})\\s(\\w{3})\\s(\\d{4})\\s(\\d{2}):(\\d{2}):{0,1}(\\d{0,2})\\s([+-]{1}\\d{4})$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("no RFC 2822 format ({$date})", $date);
             }
             $months = $this->_getDigitFromName($match[2]);
             if ($calc == 'set' || $calc == 'cmp') {
                 --$months;
                 --$month;
                 --$match[1];
                 --$day;
                 $match[3] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false);
             break;
         case self::TIMESTAMP:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $date, $this->getUnixTimestamp());
             }
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("invalid date ({$date}) operand, timestamp expected", $date);
             break;
             // additional formats
             // break intentionally omitted
         // additional formats
         // break intentionally omitted
         case self::ERA:
         case self::ERA_NAME:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('era not supported', $date);
             break;
         case self::DATES:
             try {
                 $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
                 if ($calc == 'set' || $calc == 'cmp') {
                     --$parsed['month'];
                     --$month;
                     --$parsed['day'];
                     --$day;
                     $parsed['year'] -= 1970;
                     $year -= 1970;
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::DATE_FULL:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc == 'set' || $calc == 'cmp') {
                     --$parsed['month'];
                     --$month;
                     --$parsed['day'];
                     --$day;
                     $parsed['year'] -= 1970;
                     $year -= 1970;
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::DATE_LONG:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc == 'set' || $calc == 'cmp') {
                     --$parsed['month'];
                     --$month;
                     --$parsed['day'];
                     --$day;
                     $parsed['year'] -= 1970;
                     $year -= 1970;
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::DATE_MEDIUM:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc == 'set' || $calc == 'cmp') {
                     --$parsed['month'];
                     --$month;
                     --$parsed['day'];
                     --$day;
                     $parsed['year'] -= 1970;
                     $year -= 1970;
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::DATE_SHORT:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 $parsed['year'] = self::getFullYear($parsed['year']);
                 if ($calc == 'set' || $calc == 'cmp') {
                     --$parsed['month'];
                     --$month;
                     --$parsed['day'];
                     --$day;
                     $parsed['year'] -= 1970;
                     $year -= 1970;
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year, true), $hour);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::TIMES:
             try {
                 if ($calc != 'set') {
                     $month = 1;
                     $day = 1;
                     $year = 1970;
                 }
                 $parsed = Zend_Locale_Format::getTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
                 return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::TIME_FULL:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'full'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc != 'set') {
                     $month = 1;
                     $day = 1;
                     $year = 1970;
                 }
                 return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], 0, $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::TIME_LONG:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'long'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc != 'set') {
                     $month = 1;
                     $day = 1;
                     $year = 1970;
                 }
                 return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::TIME_MEDIUM:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'medium'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc != 'set') {
                     $month = 1;
                     $day = 1;
                     $year = 1970;
                 }
                 return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case self::TIME_SHORT:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'short'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc != 'set') {
                     $month = 1;
                     $day = 1;
                     $year = 1970;
                 }
                 return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], 0, $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false);
             } catch (Zend_Locale_Exception $e) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
             // ATOM and RFC_3339 are identical
         // ATOM and RFC_3339 are identical
         case self::ATOM:
         case self::RFC_3339:
             $result = preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\d{0,4}([+-]{1}\\d{2}:\\d{2}|Z)$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, ATOM format expected", $date);
             }
             if ($calc == 'set' || $calc == 'cmp') {
                 --$match[2];
                 --$month;
                 --$match[3];
                 --$day;
                 $match[1] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case self::COOKIE:
             $result = preg_match("/^\\w{6,9},\\s(\\d{2})-(\\w{3})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})\\s.{3,20}\$/", $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, COOKIE format expected", $date);
             }
             $matchStartPos = iconv_strpos($match[0], ' ', 0, 'UTF-8') + 1;
             $match[0] = iconv_substr($match[0], $matchStartPos, iconv_strlen($match[0], 'UTF-8') - $matchStartPos, 'UTF-8');
             $months = $this->_getDigitFromName($match[2]);
             $match[3] = self::getFullYear($match[3]);
             if ($calc == 'set' || $calc == 'cmp') {
                 --$months;
                 --$month;
                 --$match[1];
                 --$day;
                 $match[3] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case self::RFC_822:
         case self::RFC_1036:
             // new RFC 822 format, identical to RFC 1036 standard
             $result = preg_match('/^\\w{0,3},{0,1}\\s{0,1}(\\d{1,2})\\s(\\w{3})\\s(\\d{2})\\s(\\d{2}):(\\d{2}):{0,1}(\\d{0,2})\\s([+-]{1}\\d{4}|\\w{1,20})$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 822 date format expected", $date);
             }
             $months = $this->_getDigitFromName($match[2]);
             $match[3] = self::getFullYear($match[3]);
             if ($calc == 'set' || $calc == 'cmp') {
                 --$months;
                 --$month;
                 --$match[1];
                 --$day;
                 $match[3] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false);
             break;
         case self::RFC_850:
             $result = preg_match('/^\\w{6,9},\\s(\\d{2})-(\\w{3})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})\\s.{3,21}$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 850 date format expected", $date);
             }
             $months = $this->_getDigitFromName($match[2]);
             $match[3] = self::getFullYear($match[3]);
             if ($calc == 'set' || $calc == 'cmp') {
                 --$months;
                 --$month;
                 --$match[1];
                 --$day;
                 $match[3] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case self::RFC_1123:
             $result = preg_match('/^\\w{0,3},{0,1}\\s{0,1}(\\d{1,2})\\s(\\w{3})\\s(\\d{2,4})\\s(\\d{2}):(\\d{2}):{0,1}(\\d{0,2})\\s([+-]{1}\\d{4}|\\w{1,20})$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 1123 date format expected", $date);
             }
             $months = $this->_getDigitFromName($match[2]);
             if ($calc == 'set' || $calc == 'cmp') {
                 --$months;
                 --$month;
                 --$match[1];
                 --$day;
                 $match[3] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case self::RSS:
             $result = preg_match('/^\\w{3},\\s(\\d{2})\\s(\\w{3})\\s(\\d{2,4})\\s(\\d{1,2}):(\\d{2}):(\\d{2})\\s.{1,21}$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RSS date format expected", $date);
             }
             $months = $this->_getDigitFromName($match[2]);
             $match[3] = self::getFullYear($match[3]);
             if ($calc == 'set' || $calc == 'cmp') {
                 --$months;
                 --$month;
                 --$match[1];
                 --$day;
                 $match[3] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case self::W3C:
             $result = preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})[+-]{1}\\d{2}:\\d{2}$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, W3C date format expected", $date);
             }
             if ($calc == 'set' || $calc == 'cmp') {
                 --$match[2];
                 --$month;
                 --$match[3];
                 --$day;
                 $match[1] -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         default:
             if (!is_numeric($date) || !empty($part)) {
                 try {
                     if (self::$_options['format_type'] == 'php') {
                         $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
                     }
                     if (empty($part)) {
                         $part = Zend_Locale_Format::getDateFormat($locale) . " ";
                         $part .= Zend_Locale_Format::getTimeFormat($locale);
                     }
                     $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $part, 'locale' => $locale, 'fix_date' => true, 'format_type' => 'iso'));
                     if (strpos(strtoupper($part), 'YY') !== false and strpos(strtoupper($part), 'YYYY') === false) {
                         $parsed['year'] = self::getFullYear($parsed['year']);
                     }
                     if ($calc == 'set' || $calc == 'cmp') {
                         if (isset($parsed['month'])) {
                             --$parsed['month'];
                         } else {
                             $parsed['month'] = 0;
                         }
                         if (isset($parsed['day'])) {
                             --$parsed['day'];
                         } else {
                             $parsed['day'] = 0;
                         }
                         if (isset($parsed['year'])) {
                             $parsed['year'] -= 1970;
                         } else {
                             $parsed['year'] = 0;
                         }
                     }
                     return $this->_assign($calc, $this->mktime(isset($parsed['hour']) ? $parsed['hour'] : 0, isset($parsed['minute']) ? $parsed['minute'] : 0, isset($parsed['second']) ? $parsed['second'] : 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], false), $this->getUnixTimestamp(), false);
                 } catch (Zend_Locale_Exception $e) {
                     if (!is_numeric($date)) {
                         require_once 'Zend/Date/Exception.php';
                         throw new Zend_Date_Exception($e->getMessage(), $date);
                     }
                 }
             }
             return $this->_assign($calc, $date, $this->getUnixTimestamp(), false);
             break;
     }
 }
Exemplo n.º 21
0
 /**
  * Indicates if the phonetic machine is enabled for the current locale
  *
  * @param string $languageCode Language code.
  *
  * @return boolean
  */
 public function isPhoneticSupported($languageCode)
 {
     $lang = strtolower(Zend_Locale_Data::getContent('en', 'language', $languageCode));
     return in_array($lang, $this->_beiderMorseLanguages);
 }
Exemplo n.º 22
0
 public function calculateDefaultTimestamp($time, $endtime)
 {
     //$now = time();
     $now = $endtime;
     //print_r($now);die;
     $deltaNormal = $time - $now;
     //$deltaNormal = $now - $time;
     $delta = abs($deltaNormal);
     $isPlus = $deltaNormal > 0;
     // Prepare data in locale timezone
     $timezone = null;
     if (Zend_Registry::isRegistered('timezone')) {
         $timezone = Zend_Registry::get('timezone');
     }
     if (null !== $timezone) {
         $prevTimezone = date_default_timezone_get();
         date_default_timezone_set($timezone);
     }
     $nowDay = date('d', $now);
     $tsDay = date('d', $time);
     $nowWeek = date('W', $now);
     $tsWeek = date('W', $time);
     $tsDayOfWeek = date('D', $time);
     if (null !== $timezone) {
         date_default_timezone_set($prevTimezone);
     }
     // Right now
     if ($delta < 1) {
         $val = null;
         if ($isPlus) {
             $key = 'now';
         } else {
             $key = 'now';
         }
     } else {
         if ($delta < 60) {
             $val = null;
             if ($isPlus) {
                 $key = 'in a few seconds';
             } else {
                 $key = 'a few seconds ago';
             }
         } else {
             if ($delta < self::HOUR) {
                 $val = floor($delta / 60);
                 if ($isPlus) {
                     $key = array('in %s minute', 'in %s minutes', $val);
                 } else {
                     $key = array('%s minute ago', '%s minutes ago', $val);
                 }
             } else {
                 if ($delta < self::HOUR * 12 || $delta < self::DAY && $tsDay == $nowDay) {
                     $val = floor($delta / (60 * 60));
                     if ($isPlus) {
                         $key = array('in %s hour', 'in %s hours', $val);
                     } else {
                         $key = array('%s hour ago', '%s hours ago', $val);
                     }
                 } else {
                     if ($delta < self::WEEK && $tsWeek == $nowWeek) {
                         // Get day of week
                         $dayOfWeek = Zend_Locale_Data::getContent(Zend_Registry::get('Locale'), 'day', array('gregorian', 'format', 'abbreviated', strtolower($tsDayOfWeek)));
                         return $this->view->translate('%s at %s', $dayOfWeek, $this->view->locale()->toTime($time, array('size' => 'short')));
                     } else {
                         if ($delta < self::YEAR && date('Y', $time) == date('Y', $now)) {
                             return $this->view->locale()->toTime($time, array('type' => 'dateitem', 'size' => 'MMMMd'));
                         } else {
                             return $this->view->locale()->toDate($time, array('size' => 'long'));
                         }
                     }
                 }
             }
         }
     }
     $this->_extraClass = 'timestamp-update';
     $translator = $this->view->getHelper('translate');
     if ($translator) {
         return $translator->translate($key, $val);
     } else {
         $key = is_array($string) ? $string[0] : $key;
         return sprintf($string, $val);
     }
 }
Exemplo n.º 23
0
 /**
  * Returns an array with translated yes strings
  *
  * @param  string  $locale  OPTIONAL locale for language translation (defaults to $this locale)
  * @return array
  */
 public function getQuestion($locale = null)
 {
     if ($locale === null) {
         $locale = $this->_Locale;
     }
     $quest = Zend_Locale_Data::getContent($locale, 'questionstrings');
     $yes = explode(':', $quest['yes']);
     $no = explode(':', $quest['no']);
     $quest['yes'] = $yes[0];
     $quest['yesabbr'] = $yes[1];
     $quest['no'] = $no[0];
     $quest['noabbr'] = $no[1];
     return $quest;
 }
Exemplo n.º 24
0
 /**
  * test for rerouting in LDML
  * expected array
  */
 public function testLDMLReadingReRouting()
 {
     $value = Zend_Locale_Data::getContent('az_AZ', 'language', 'az');
     $this->assertTrue(is_array($value), 'array expected');
 }
Exemplo n.º 25
0
 /**
  * Returns an array with translated yes strings
  * 
  * @return array
  */
 public function getQuestion()
 {
     $quest = Zend_Locale_Data::getContent($this->_Locale, 'questionstrings');
     $yes = explode(':', $quest['yes']);
     $no = explode(':', $quest['no']);
     $ret['yes'] = $yes[0];
     $ret['yesabbr'] = $yes[1];
     $ret['no'] = $no[0];
     $ret['noabbr'] = $no[1];
     return $ret;
 }
Exemplo n.º 26
0
 /**
  * Returns an array with translated yes strings
  *
  * @param  string  $locale  OPTIONAL locale for language translation (defaults to $this locale)
  * @return array
  */
 public function getQuestion($locale = null)
 {
     // load class within method for speed
     require_once 'Zend/Locale/Data.php';
     if ($locale === null) {
         $locale = $this->_Locale;
     }
     if ($locale == 'auto') {
         $locale = self::$_auto;
     }
     if ($locale == 'browser') {
         $locale = self::$_browser;
     }
     if ($locale == 'environment') {
         $locale = self::$_environment;
     }
     if (is_array($locale)) {
         $locale = key($locale);
     }
     $quest = Zend_Locale_Data::getContent($locale, 'question');
     $yes = explode(':', $quest['yes']);
     $no = explode(':', $quest['no']);
     $quest['yes'] = $yes[0];
     $quest['yesarray'] = $yes;
     $quest['no'] = $no[0];
     $quest['noarray'] = $no;
     $quest['yesexpr'] = $this->_getRegex($yes);
     $quest['noexpr'] = $this->_getRegex($no);
     return $quest;
 }
Exemplo n.º 27
0
    /**
     * test setOption
     * expected boolean
     */
    public function testSetOption()
    {
        $this->assertEquals(7, count(Zend_Locale_Format::setOptions(array('format_type' => 'php'))));
        $this->assertTrue(is_array(Zend_Locale_Format::setOptions()));

        try {
            $this->assertTrue(Zend_Locale_Format::setOptions(array('format_type' => 'xxx')));
            $this->fail("exception expected");
        } catch (Zend_Locale_Exception $e) {
            // success
        }
        try {
            $this->assertTrue(Zend_Locale_Format::setOptions(array('myformat' => 'xxx')));
            $this->fail("exception expected");
        } catch (Zend_Locale_Exception $e) {
            // success
        }

        $format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'number_format' => Zend_Locale_Format::STANDARD));
        $test   = Zend_Locale_Data::getContent('de', 'decimalnumberformat');
        $this->assertEquals($test['default'], $format['number_format']);

        try {
            $this->assertFalse(Zend_Locale_Format::setOptions(array('number_format' => array('x' => 'x'))));
            $this->fail("exception expected");
        } catch (Zend_Locale_Exception $e) {
            // success
        }

        $format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'date_format' => Zend_Locale_Format::STANDARD));
        $test   = Zend_Locale_Format::getDateFormat('de');
        $this->assertEquals($test, $format['date_format']);

        try {
            $this->assertFalse(Zend_Locale_Format::setOptions(array('date_format' => array('x' => 'x'))));
            $this->fail("exception expected");
        } catch (Zend_Locale_Exception $e) {
            // success
        }
        try {
            $this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('fix_date' => 'no'))));
            $this->fail("exception expected");
        } catch (Zend_Locale_Exception $e) {
            // success
        }

        $format = Zend_Locale_Format::setOptions(array('locale' => Zend_Locale_Format::STANDARD));
        $locale = new Zend_Locale();
        $this->assertEquals($locale, $format['locale']);

        try {
            $this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('locale' => 'nolocale'))));
            $this->fail("exception expected");
        } catch (Zend_Locale_Exception $e) {
            // success
        }
        try {
            $this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('precision' => 50))));
            $this->fail("exception expected");
        } catch (Zend_Locale_Exception $e) {
            // success
        }
        // test interaction between class-wide default date format and using locale's default format
        try {
            $result = array('date_format' => 'MMM d, yyyy', 'locale' => 'en_US', 'month' => '07',
                    'day' => '4', 'year' => '2007');
            Zend_Locale_Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, yyyy', 'locale' => 'en_US')); // test setUp
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        try {
            // uses global date_format with global locale
            $this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007'));
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        try {
            // uses global date_format with given locale
            $this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US')));
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        try {
            // sets a new global date format
            Zend_Locale_Format::setOptions(array('date_format' => 'M-d-y'));
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        try {
            // uses global date format with given locale
            // but this date format differs from the original set... (MMMM d, yyyy != M-d-y)
            $expected = Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US'));
            $this->assertSame($expected['year'],  $result['year'] );
            $this->assertSame($expected['month'], $result['month']);
            $this->assertSame($expected['day'],   $result['day']  );
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        try {
            // the following should not be used... instead of null, Zend_Locale_Format::STANDARD should be used
            // uses given local with standard format from this locale
            $this->assertSame($result,
                Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => null)));
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        try {
            // uses given locale with standard format from this locale
            $this->assertSame($result,
                Zend_Locale_Format::getDate('July 4, 2007',
                    array('locale' => 'en_US', 'date_format' => Zend_Locale_Format::STANDARD)));
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        try {
            // uses standard locale with standard format from this locale
            $expect = Zend_Locale_Format::getDate('July 4, 2007', array('locale' => Zend_Locale_Format::STANDARD));
            $testlocale = new Zend_Locale();
            $this->assertEquals($testlocale, $expect['locale']);
        } catch (Zend_Locale_Exception $e) {
            $this->fail("exception expected");
        }
        Zend_Locale_Format::setOptions(array('date_format' => null, 'locale' => null)); // test tearDown
    }
Exemplo n.º 28
0
 /**
  * Returns a list of currencies which are used in this region
  * a region name should be 2 charachters only (f.e. EG, DE, US)
  * If no region is given, the actual region is used
  *
  * @param  string $region OPTIONAL Region to return the currencies for
  * @return array List of currencies
  */
 public function getCurrencyList($region = null)
 {
     if (empty($region) === true) {
         if (strlen($this->_options['locale']) > 4) {
             $region = substr($this->_options['locale'], strpos($this->_options['locale'], '_') + 1);
         }
     }
     $data = Zend_Locale_Data::getContent($this->_options['locale'], 'currencytoregion', $region);
     $result = explode(' ', $data);
     return $result;
 }
Exemplo n.º 29
0
 /**
  * get index settings
  *
  * @todo make this cacheable via magento cache backend
  * @todo later optimize analyzer
  * @todo later implement synonyms
  * @return array
  */
 public function getIndexSettings()
 {
     if (false === isset($this->_settingsCache[$this->getStoreId()])) {
         $indexSettings = array();
         $indexSettings['number_of_shards'] = Mage::helper('elasticgento/config')->getNumberOfShards();
         $indexSettings['number_of_replicas'] = Mage::helper('elasticgento/config')->getNumberOfReplicas();
         // define analyzer
         $indexSettings['analysis']['analyzer'] = array('whitespace' => array('tokenizer' => 'standard', 'filter' => array('lowercase')), 'edge_ngram_front' => array('tokenizer' => 'standard', 'filter' => array('length', 'edge_ngram_front', 'lowercase')), 'edge_ngram_back' => array('tokenizer' => 'standard', 'filter' => array('length', 'edge_ngram_back', 'lowercase')), 'shingle' => array('tokenizer' => 'standard', 'filter' => array('shingle', 'length', 'lowercase')), 'shingle_strip_ws' => array('tokenizer' => 'standard', 'filter' => array('shingle', 'strip_whitespaces', 'length', 'lowercase')), 'shingle_strip_apos_and_ws' => array('tokenizer' => 'standard', 'filter' => array('shingle', 'strip_apostrophes', 'strip_whitespaces', 'length', 'lowercase')));
         // define filters
         $indexSettings['analysis']['filter'] = array('shingle' => array('type' => 'shingle', 'max_shingle_size' => 5, 'output_unigrams' => true), 'strip_whitespaces' => array('type' => 'pattern_replace', 'pattern' => '\\s', 'replacement' => ''), 'strip_apostrophes' => array('type' => 'pattern_replace', 'pattern' => "'", 'replacement' => ''), 'edge_ngram_front' => array('type' => 'edgeNGram', 'min_gram' => 3, 'max_gram' => 8, 'side' => 'front'), 'edge_ngram_back' => array('type' => 'edgeNGram', 'min_gram' => 3, 'max_gram' => 8, 'side' => 'back'), 'length' => array('type' => 'length', 'min' => 2));
         $languageCode = $this->getLanguageCodeByStore();
         $language = Zend_Locale_Data::getContent('en_GB', 'language', $languageCode);
         if (true === in_array($language, $this->_supportedLanguages)) {
             $indexSettings['analysis']['analyzer']['analyzer_' . $languageCode] = array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('length', 'lowercase', 'snowball_' . $languageCode));
             $indexSettings['analysis']['filter']['snowball_' . $languageCode] = array('type' => 'snowball', 'language' => $language);
         }
         $indexSettings['language'] = $language;
         $indexSettings['language_code'] = $languageCode;
         $this->_settingsCache[$this->getStoreId()] = $indexSettings;
     }
     return $this->_settingsCache[$this->getStoreId()];
 }
Exemplo n.º 30
0
 /**
  * Returns a list of currencies which are used in this region
  * a region name should be 2 charachters only (f.e. EG, DE, US)
  *
  * @param  string  $region  Currency Type
  * @return array            List of currencys
  */
 public static function getCurrencyList($region)
 {
     return Zend_Locale_Data::getContent('', 'currencyforregion', $region);
 }