Esempio n. 1
0
 protected function createTimeFormatFieldForMember($member)
 {
     require_once 'Zend/Date.php';
     $defaultTimeFormat = Zend_Locale_Format::getTimeFormat($member->Locale);
     $timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
     $timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . ' (default)';
     $field = new Member_DatetimeOptionsetField('TimeFormat', 'Time format', $timeFormatMap);
     $field->setValue($member->TimeFormat);
     return $field;
 }
Esempio n. 2
0
 /**
  * Set/Install the given locale.
  * This does set the i18n locale as well as the Translatable or Fluent locale (if any of these modules is installed)
  * @param string $locale the locale to install
  * @throws Zend_Locale_Exception @see Zend_Locale_Format::getDateFormat and @see Zend_Locale_Format::getTimeFormat
  */
 public static function install_locale($locale)
 {
     // If the locale isn't given, silently fail (there might be carts that still have locale set to null)
     if (empty($locale)) {
         return;
     }
     if (class_exists('Translatable')) {
         Translatable::set_current_locale($locale);
     } else {
         if (class_exists('Fluent')) {
             Fluent::set_persist_locale($locale);
         }
     }
     // Do something like Fluent does to install the locale
     i18n::set_locale($locale);
     // LC_NUMERIC causes SQL errors for some locales (comma as decimal indicator) so skip
     foreach (array(LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_TIME) as $category) {
         setlocale($category, "{$locale}.UTF-8", $locale);
     }
     // Get date/time formats from Zend
     require_once 'Zend/Date.php';
     i18n::config()->date_format = Zend_Locale_Format::getDateFormat($locale);
     i18n::config()->time_format = Zend_Locale_Format::getTimeFormat($locale);
 }
Esempio n. 3
0
 /**
  * Return a {@link FieldSet} of fields that would appropriate for editing
  * this member.
  *
  * @return FieldSet Return a FieldSet of fields that would appropriate for
  *                  editing this member.
  */
 public function getCMSFields()
 {
     require_once 'Zend/Date.php';
     $fields = parent::getCMSFields();
     $mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children;
     $password = new ConfirmedPasswordField('Password', null, null, null, true);
     $password->setCanBeEmpty(true);
     if (!$this->ID) {
         $password->showOnClick = false;
     }
     $mainFields->replaceField('Password', $password);
     $mainFields->insertBefore(new HeaderField('MemberDetailsHeader', _t('Member.PERSONALDETAILS', "Personal Details", PR_MEDIUM, 'Headline for formfields')), 'FirstName');
     $mainFields->insertBefore(new HeaderField('MemberUserDetailsHeader', _t('Member.USERDETAILS', "User Details", PR_MEDIUM, 'Headline for formfields')), 'Email');
     $mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", PR_MEDIUM, 'Language of the CMS'), i18n::get_existing_translations()));
     $mainFields->removeByName('Bounced');
     $mainFields->removeByName('RememberLoginToken');
     $mainFields->removeByName('AutoLoginHash');
     $mainFields->removeByName('AutoLoginExpired');
     $mainFields->removeByName('PasswordEncryption');
     $mainFields->removeByName('PasswordExpiry');
     $mainFields->removeByName('LockedOutUntil');
     if (!self::$lock_out_after_incorrect_logins) {
         $mainFields->removeByName('FailedLoginCount');
     }
     $mainFields->removeByName('Salt');
     $mainFields->removeByName('NumVisit');
     $mainFields->removeByName('LastVisited');
     $fields->removeByName('Subscriptions');
     // Groups relation will get us into logical conflicts because
     // Members are displayed within  group edit form in SecurityAdmin
     $fields->removeByName('Groups');
     if (Permission::check('EDIT_PERMISSIONS')) {
         $groupsField = new TreeMultiselectField('Groups', false, 'Group');
         $fields->findOrMakeTab('Root.Groups', singleton('Group')->i18n_plural_name());
         $fields->addFieldToTab('Root.Groups', $groupsField);
         // Add permission field (readonly to avoid complicated group assignment logic).
         // This should only be available for existing records, as new records start
         // with no permissions until they have a group assignment anyway.
         if ($this->ID) {
             $permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', singleton('Permission')->i18n_plural_name(), 'Permission', 'GroupID', $this->getManyManyComponents('Groups'));
             $fields->findOrMakeTab('Root.Permissions', singleton('Permission')->i18n_plural_name());
             $fields->addFieldToTab('Root.Permissions', $permissionsField);
         }
     }
     $defaultDateFormat = Zend_Locale_Format::getDateFormat($this->Locale);
     $dateFormatMap = array('MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'), 'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'), 'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'), 'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'));
     $dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
     $mainFields->push($dateFormatField = new Member_DatetimeOptionsetField('DateFormat', $this->fieldLabel('DateFormat'), $dateFormatMap));
     $dateFormatField->setValue($this->DateFormat);
     $defaultTimeFormat = Zend_Locale_Format::getTimeFormat($this->Locale);
     $timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
     $timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
     $mainFields->push($timeFormatField = new Member_DatetimeOptionsetField('TimeFormat', $this->fieldLabel('TimeFormat'), $timeFormatMap));
     $timeFormatField->setValue($this->TimeFormat);
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 /**
  * 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 ($date === null) {
         require_once 'Zend/Date/Exception.php';
         throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');
     }
     if ($part !== null && strlen($part) !== 2 && Zend_Locale::isLocale($part, null, false)) {
         $locale = $part;
         $part = null;
     }
     if ($locale === null) {
         $locale = $this->getLocale();
     }
     $locale = (string) $locale;
     // Create date parts
     $year = $this->toString(self::YEAR, 'iso');
     $month = $this->toString(self::MONTH_SHORT, 'iso');
     $day = $this->toString(self::DAY_SHORT, 'iso');
     $hour = $this->toString(self::HOUR_SHORT, 'iso');
     $minute = $this->toString(self::MINUTE_SHORT, 'iso');
     $second = $this->toString(self::SECOND_SHORT, 'iso');
     // If object extract value
     if ($date instanceof Zend_Date) {
         $date = $date->toString($part, 'iso', $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", 0, null, $date);
             break;
         case self::WEEKDAY_SHORT:
             $daylist = Zend_Locale_Data::getList($locale, 'day');
             $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $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", 0, null, $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", 0, null, $date);
             break;
         case self::WEEKDAY:
             $daylist = Zend_Locale_Data::getList($locale, 'day');
             $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $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", 0, null, $date);
             break;
         case self::WEEKDAY_8601:
             $weekday = (int) $this->toString(self::WEEKDAY_8601, 'iso', $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", 0, null, $date);
             break;
         case self::DAY_SUFFIX:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('day suffix not supported', 0, null, $date);
             break;
         case self::WEEKDAY_DIGIT:
             $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $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", 0, null, $date);
             break;
         case self::DAY_OF_YEAR:
             if (is_numeric($date)) {
                 if ($calc == 'add' || $calc == 'sub') {
                     $year = 1970;
                     ++$date;
                     ++$day;
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, 1, $date, $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, day expected", 0, null, $date);
             break;
         case self::WEEKDAY_NARROW:
             $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated'));
             $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $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", 0, null, $date);
             break;
         case self::WEEKDAY_NAME:
             $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated'));
             $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $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", 0, null, $date);
             break;
             // week formats
         // week formats
         case self::WEEK:
             if (is_numeric($date)) {
                 $week = (int) $this->toString(self::WEEK, 'iso', $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", 0, null, $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($hour, $minute, $second, $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($hour, $minute, $second, $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", 0, null, $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($hour, $minute, $second, $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($hour, $minute, $second, $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", 0, null, $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($hour, $minute, $second, $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($hour, $minute, $second, $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", 0, null, $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($hour, $minute, $second, $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($hour, $minute, $second, $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", 0, null, $date);
             break;
         case self::MONTH_DAYS:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('month days not supported', 0, null, $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($hour, $minute, $second, $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($hour, $minute, $second, $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", 0, null, $date);
             break;
             // year formats
         // year formats
         case self::LEAPYEAR:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('leap year not supported', 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $date);
             break;
             // time formats
         // time formats
         case self::MERIDIEM:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('meridiem not supported', 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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', 0, null, $date);
             break;
         case self::DAYLIGHT:
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception('daylight not supported', 0, null, $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', 0, null, $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})", 0, null, $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}|\\w{1,20})$/', $date, $match);
             if (!$result) {
                 require_once 'Zend/Date/Exception.php';
                 throw new Zend_Date_Exception("no RFC 2822 format ({$date})", 0, null, $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", 0, null, $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', 0, null, $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(), 0, $e, $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(), 0, $e, $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(), 0, $e, $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(), 0, $e, $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(), 0, $e, $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(), 0, $e, $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;
                 }
                 if (!isset($parsed['second'])) {
                     $parsed['second'] = 0;
                 }
                 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(), 0, $e, $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(), 0, $e, $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(), 0, $e, $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;
                 }
                 if (!isset($parsed['second'])) {
                     $parsed['second'] = 0;
                 }
                 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(), 0, $e, $date);
             }
             break;
         case self::DATETIME:
             try {
                 $parsed = Zend_Locale_Format::getDateTime($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($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 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(), 0, $e, $date);
             }
             break;
         case self::DATETIME_FULL:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full'));
                 $parsed = Zend_Locale_Format::getDateTime($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;
                 }
                 if (!isset($parsed['second'])) {
                     $parsed['second'] = 0;
                 }
                 return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 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(), 0, $e, $date);
             }
             break;
         case self::DATETIME_LONG:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long'));
                 $parsed = Zend_Locale_Format::getDateTime($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($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 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(), 0, $e, $date);
             }
             break;
         case self::DATETIME_MEDIUM:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium'));
                 $parsed = Zend_Locale_Format::getDateTime($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($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 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(), 0, $e, $date);
             }
             break;
         case self::DATETIME_SHORT:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short'));
                 $parsed = Zend_Locale_Format::getDateTime($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;
                 }
                 if (!isset($parsed['second'])) {
                     $parsed['second'] = 0;
                 }
                 return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 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(), 0, $e, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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", 0, null, $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 (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;
                         }
                     }
                     return $this->_assign($calc, $this->mktime(isset($parsed['hour']) ? $parsed['hour'] : 0, isset($parsed['minute']) ? $parsed['minute'] : 0, isset($parsed['second']) ? $parsed['second'] : 0, isset($parsed['month']) ? 1 + $parsed['month'] : 1, isset($parsed['day']) ? 1 + $parsed['day'] : 1, $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(), 0, $e, $date);
                     }
                 }
             }
             return $this->_assign($calc, $date, $this->getUnixTimestamp(), false);
             break;
     }
 }
Esempio n. 5
0
 /**
  * @return string ISO time format
  */
 public static function get_time_format()
 {
     require_once 'Zend/Date.php';
     return self::$time_format ? self::$time_format : Zend_Locale_Format::getTimeFormat(self::get_locale());
 }
Esempio n. 6
0
 /**
  * Return a {@link FieldList} of fields that would appropriate for editing
  * this member.
  *
  * @return FieldList Return a FieldList of fields that would appropriate for
  *                   editing this member.
  */
 public function getCMSFields()
 {
     require_once 'Zend/Date.php';
     $self = $this;
     $this->beforeUpdateCMSFields(function ($fields) use($self) {
         $mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children;
         $password = new ConfirmedPasswordField('Password', null, null, null, true);
         $password->setCanBeEmpty(true);
         if (!$self->ID) {
             $password->showOnClick = false;
         }
         $mainFields->replaceField('Password', $password);
         $mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", 'Language of the CMS'), i18n::get_existing_translations()));
         $mainFields->removeByName('RememberLoginToken');
         $mainFields->removeByName('AutoLoginHash');
         $mainFields->removeByName('AutoLoginExpired');
         $mainFields->removeByName('PasswordEncryption');
         $mainFields->removeByName('PasswordExpiry');
         $mainFields->removeByName('LockedOutUntil');
         if (!$self->config()->lock_out_after_incorrect_logins) {
             $mainFields->removeByName('FailedLoginCount');
         }
         $mainFields->removeByName('Salt');
         $mainFields->removeByName('NumVisit');
         $mainFields->makeFieldReadonly('LastVisited');
         $fields->removeByName('Subscriptions');
         // Groups relation will get us into logical conflicts because
         // Members are displayed within  group edit form in SecurityAdmin
         $fields->removeByName('Groups');
         if (Permission::check('EDIT_PERMISSIONS')) {
             $groupsMap = array();
             foreach (Group::get() as $group) {
                 // Listboxfield values are escaped, use ASCII char instead of &raquo;
                 $groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
             }
             asort($groupsMap);
             $fields->addFieldToTab('Root.Main', ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())->setMultiple(true)->setSource($groupsMap)->setAttribute('data-placeholder', _t('Member.ADDGROUP', 'Add group', 'Placeholder text for a dropdown')));
             // Add permission field (readonly to avoid complicated group assignment logic).
             // This should only be available for existing records, as new records start
             // with no permissions until they have a group assignment anyway.
             if ($self->ID) {
                 $permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', false, 'Permission', 'GroupID', $self->getManyManyComponents('Groups'));
                 $fields->findOrMakeTab('Root.Permissions', singleton('Permission')->i18n_plural_name());
                 $fields->addFieldToTab('Root.Permissions', $permissionsField);
             }
         }
         $permissionsTab = $fields->fieldByName("Root")->fieldByName('Permissions');
         if ($permissionsTab) {
             $permissionsTab->addExtraClass('readonly');
         }
         $defaultDateFormat = Zend_Locale_Format::getDateFormat(new Zend_Locale($self->Locale));
         $dateFormatMap = array('MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'), 'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'), 'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'), 'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'));
         $dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
         $mainFields->push($dateFormatField = new MemberDatetimeOptionsetField('DateFormat', $self->fieldLabel('DateFormat'), $dateFormatMap));
         $dateFormatField->setValue($self->DateFormat);
         $defaultTimeFormat = Zend_Locale_Format::getTimeFormat(new Zend_Locale($self->Locale));
         $timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
         $timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
         $mainFields->push($timeFormatField = new MemberDatetimeOptionsetField('TimeFormat', $self->fieldLabel('TimeFormat'), $timeFormatMap));
         $timeFormatField->setValue($self->TimeFormat);
     });
     return parent::getCMSFields();
 }
Esempio n. 7
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)) {
         throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');
     }
     if (Zend_Locale::isLocale($part)) {
         $locale = $part;
         $part = null;
     }
     if ($locale === null) {
         $locale = $this->getLocale();
     }
     if ($locale instanceof Zend_Locale) {
         $locale = $locale->toString();
     }
     // create date parts
     $year = $this->get(Zend_Date::YEAR);
     $month = $this->get(Zend_Date::MONTH_SHORT);
     $day = $this->get(Zend_Date::DAY_SHORT);
     $hour = $this->get(Zend_Date::HOUR_SHORT);
     $minute = $this->get(Zend_Date::MINUTE_SHORT);
     $second = $this->get(Zend_Date::SECOND_SHORT);
     // if object extract value
     if ($date instanceof Zend_Date) {
         $date = $date->get($part, $locale);
     }
     if (is_array($date)) {
         if (!empty($part)) {
             switch ($part) {
                 // Fall through
                 case Zend_Date::DAY:
                 case Zend_Date::DAY_SHORT:
                     if (array_key_exists('day', $date)) {
                         $date = $date['day'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case Zend_Date::WEEKDAY_SHORT:
                 case Zend_Date::WEEKDAY:
                 case Zend_Date::WEEKDAY_8601:
                 case Zend_Date::WEEKDAY_DIGIT:
                 case Zend_Date::WEEKDAY_NARROW:
                 case Zend_Date::WEEKDAY_NAME:
                     if (array_key_exists('weekday', $date)) {
                         $date = $date['weekday'];
                         $part = Zend_Date::WEEKDAY_DIGIT;
                     }
                     break;
                 case Zend_Date::DAY_OF_YEAR:
                     if (array_key_exists('day_of_year', $date)) {
                         $date = $date['day_of_year'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case Zend_Date::MONTH:
                 case Zend_Date::MONTH_SHORT:
                 case Zend_Date::MONTH_NAME:
                 case Zend_Date::MONTH_NAME_SHORT:
                 case Zend_Date::MONTH_NAME_NARROW:
                     if (array_key_exists('month', $date)) {
                         $date = $date['month'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case Zend_Date::YEAR:
                 case Zend_Date::YEAR_SHORT:
                 case Zend_Date::YEAR_8601:
                 case Zend_Date::YEAR_SHORT_8601:
                     if (array_key_exists('year', $date)) {
                         $date = $date['year'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case Zend_Date::HOUR:
                 case Zend_Date::HOUR_AM:
                 case Zend_Date::HOUR_SHORT:
                 case Zend_Date::HOUR_SHORT_AM:
                     if (array_key_exists('hour', $date)) {
                         $date = $date['hour'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case Zend_Date::MINUTE:
                 case Zend_Date::MINUTE_SHORT:
                     if (array_key_exists('minute', $date)) {
                         $date = $date['minute'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case Zend_Date::SECOND:
                 case Zend_Date::SECOND_SHORT:
                     if (array_key_exists('second', $date)) {
                         $date = $date['second'];
                     }
                     break;
                     // Fall through
                 // Fall through
                 case Zend_Date::TIMEZONE:
                 case Zend_Date::TIMEZONE_NAME:
                     if (array_key_exists('timezone', $date)) {
                         $date = $date['timezone'];
                     }
                     break;
                 case Zend_Date::TIMESTAMP:
                     if (array_key_exists('timestamp', $date)) {
                         $date = $date['timestamp'];
                     }
                     break;
                 case Zend_Date::WEEK:
                     if (array_key_exists('week', $date)) {
                         $date = $date['week'];
                     }
                     break;
                 case Zend_Date::TIMEZONE_SECS:
                     if (array_key_exists('gmtsecs', $date)) {
                         $date = $date['gmtsecs'];
                     }
                     break;
                 default:
                     throw new Zend_Date_Exception("datepart for part ({$part}) not found in array");
                     break;
             }
         } else {
             $hours = 0;
             if (array_key_exists("hour", $date)) {
                 $hours = $date['hour'];
             }
             $minutes = 0;
             if (array_key_exists('minute', $date)) {
                 $minutes = $date['minute'];
             }
             $seconds = 0;
             if (array_key_exists('second', $date)) {
                 $seconds = $date['second'];
             }
             $months = 0;
             if (array_key_exists('month', $date)) {
                 $months = $date['month'];
             }
             $days = 0;
             if (array_key_exists('day', $date)) {
                 $days = $date['day'];
             }
             $years = 0;
             if (array_key_exists('year', $date)) {
                 $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 Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", $date);
             break;
         case Zend_Date::WEEKDAY_SHORT:
             $daylist = Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'wide'));
             $weekday = (int) $this->get(Zend_Date::WEEKDAY_DIGIT, $locale);
             $cnt = 0;
             foreach ($daylist as $key => $value) {
                 if (strtoupper(substr($value, 0, 3)) == 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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", $date);
             break;
         case Zend_Date::WEEKDAY:
             $daylist = Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'wide'));
             $weekday = (int) $this->get(Zend_Date::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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case Zend_Date::WEEKDAY_8601:
             $weekday = (int) $this->get(Zend_Date::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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case Zend_Date::DAY_SUFFIX:
             throw new Zend_Date_Exception('day suffix not supported', $date);
             break;
         case Zend_Date::WEEKDAY_DIGIT:
             $weekday = (int) $this->get(Zend_Date::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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, day expected", $date);
             break;
         case Zend_Date::WEEKDAY_NARROW:
             $daylist = Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'abbreviated'));
             $weekday = (int) $this->get(Zend_Date::WEEKDAY_DIGIT, $locale);
             $cnt = 0;
             foreach ($daylist as $key => $value) {
                 if (strtoupper(substr($value, 0, 1)) == 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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
         case Zend_Date::WEEKDAY_NAME:
             $daylist = Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'abbreviated'));
             $weekday = (int) $this->get(Zend_Date::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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, weekday expected", $date);
             break;
             // week formats
         // week formats
         case Zend_Date::WEEK:
             if (is_numeric($date)) {
                 $week = (int) $this->get(Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, week expected", $date);
             break;
             // month formats
         // month formats
         case Zend_Date::MONTH_NAME:
             $monthlist = Zend_Locale_Data::getContent($locale, 'monthlist', array('gregorian', 'format', 'wide'));
             $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'];
                         }
                     }
                 } 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'];
                             }
                         }
                     }
                 }
                 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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case Zend_Date::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'];
                         }
                     }
                 } 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'];
                             }
                         }
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case Zend_Date::MONTH_NAME_SHORT:
             $monthlist = Zend_Locale_Data::getContent($locale, 'monthlist', 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'];
                         }
                     }
                 } 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'];
                             }
                         }
                     }
                 }
                 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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case Zend_Date::MONTH_SHORT:
             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'];
                         }
                     }
                 } 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'];
                             }
                         }
                     }
                 }
                 return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true), $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
         case Zend_Date::MONTH_DAYS:
             throw new Zend_Date_Exception('month days not supported', $date);
             break;
         case Zend_Date::MONTH_NAME_NARROW:
             $monthlist = Zend_Locale_Data::getContent($locale, 'monthlist', 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'];
                         }
                     }
                 } 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'];
                             }
                         }
                     }
                 }
                 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
             throw new Zend_Date_Exception("invalid date ({$date}) operand, month expected", $date);
             break;
             // year formats
         // year formats
         case Zend_Date::LEAPYEAR:
             throw new Zend_Date_Exception('leap year not supported', $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
         case Zend_Date::YEAR_SHORT:
             if (is_numeric($date)) {
                 $date = intval($date);
                 if ($date >= 0 and $date <= 100 and $calc == 'set') {
                     $date += 1900;
                     if ($date < 1970) {
                         $date += 100;
                     }
                 }
                 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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
         case Zend_Date::YEAR_SHORT_8601:
             if (is_numeric($date)) {
                 $date = intval($date);
                 if ($date >= 0 and $date <= 100 and $calc == 'set') {
                     $date += 1900;
                     if ($date < 1970) {
                         $date += 100;
                     }
                 }
                 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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, year expected", $date);
             break;
             // time formats
         // time formats
         case Zend_Date::MERIDIEM:
             throw new Zend_Date_Exception('meridiem not supported', $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, swatchstamp expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, hour expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, minute expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, second expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, milliseconds expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, minute expected", $date);
             break;
         case Zend_Date::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);
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, second expected", $date);
             break;
             // timezone formats
             // break intentionally omitted
         // timezone formats
         // break intentionally omitted
         case Zend_Date::TIMEZONE_NAME:
         case Zend_Date::TIMEZONE:
         case Zend_Date::TIMEZONE_SECS:
             throw new Zend_Date_Exception('timezone not supported', $date);
             break;
         case Zend_Date::DAYLIGHT:
             throw new Zend_Date_Exception('daylight not supported', $date);
             break;
         case Zend_Date::GMT_DIFF:
         case Zend_Date::GMT_DIFF_SEP:
             throw new Zend_Date_Exception('gmtdiff not supported', $date);
             break;
             // date strings
         // date strings
         case Zend_Date::ISO_8601:
             $next = 0;
             if (preg_match('/-\\d{4}-\\d{2}-\\d{2}/', $date, $datematch)) {
                 // -yyyy-mm-dd
                 $minus = true;
                 $result = array('Y' => 1, 'M' => 6, 'd' => 9);
                 $next = 11;
             } else {
                 if (preg_match('/\\d{4}-\\d{2}-\\d{2}/', $date, $datematch)) {
                     // yyyy-mm-dd
                     $result = array('Y' => 0, 'M' => 5, 'd' => 8);
                     $next = 10;
                 } else {
                     if (preg_match('/-\\d{2}-\\d{2}-\\d{2}/', $date, $datematch)) {
                         // -yy-mm-dd
                         $minus = true;
                         $result = array('y' => 1, 'M' => 4, 'd' => 7);
                         $next = 9;
                     } else {
                         if (preg_match('/\\d{2}-\\d{2}-\\d{2}/', $date, $datematch)) {
                             // yy-mm-dd
                             $result = array('y' => 0, 'M' => 3, 'd' => 6);
                             $next = 8;
                         } else {
                             if (preg_match('/-\\d{8}/', $date, $datematch)) {
                                 // -yyyymmdd
                                 $minus = true;
                                 $result = array('Y' => 1, 'M' => 5, 'd' => 7);
                                 $next = 9;
                             } else {
                                 if (preg_match('/\\d{8}/', $date, $datematch)) {
                                     // yyyymmdd
                                     $result = array('Y' => 0, 'M' => 4, 'd' => 6);
                                     $next = 8;
                                 } else {
                                     if (preg_match('/-\\d{6}/', $date, $datematch)) {
                                         // -yymmdd
                                         $minus = true;
                                         $result = array('y' => 1, 'M' => 3, 'd' => 5);
                                         $next = 7;
                                     } else {
                                         if (preg_match('/\\d{6}/', $date, $datematch)) {
                                             // yymmdd
                                             $result = array('y' => 0, 'M' => 2, 'd' => 4);
                                             $next = 6;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (strlen($date) > $next) {
                 $date = substr($date, $next);
                 // Thh:mm:ss
                 if (preg_match('/[T,\\s]{1}\\d{2}:\\d{2}:\\d{2}/', $date, $timematch)) {
                     // Thh:mm:ss | _hh:mm:ss
                     $result['h'] = 1;
                     $result['m'] = 4;
                     $result['s'] = 7;
                     $next += 9;
                 } else {
                     if (preg_match('/\\d{2}:\\d{2}:\\d{2}/', $date, $timematch)) {
                         // hh:mm:ss
                         $result['h'] = 0;
                         $result['m'] = 3;
                         $result['s'] = 6;
                         $next += 8;
                     } else {
                         if (preg_match('/[T,\\s]{1}\\d{2}\\d{2}\\d{2}/', $date, $timematch)) {
                             // Thhmmss | _hhmmss
                             $result['h'] = 1;
                             $result['m'] = 3;
                             $result['s'] = 5;
                             $next += 7;
                         } else {
                             if (preg_match('/\\d{2}\\d{2}\\d{2}/', $date, $timematch)) {
                                 // hhmmss | hhmmss
                                 $result['h'] = 0;
                                 $result['m'] = 2;
                                 $result['s'] = 4;
                                 $next += 6;
                             }
                         }
                     }
                 }
             }
             if (!isset($result)) {
                 throw new Zend_Date_Exception("unsupported ISO8601 format ({$date})", $date);
             }
             if (isset($result['M'])) {
                 if (isset($result['Y'])) {
                     $years = substr($datematch[0], $result['Y'], 4);
                     if (isset($minus)) {
                         $years = 0 - $years;
                     }
                 } else {
                     $years = substr($datematch[0], $result['y'], 2);
                     if (isset($minus)) {
                         $years = 0 - $years;
                     }
                     if ($years >= 0) {
                         $years += 1900;
                         if ($years < 1970) {
                             $years += 100;
                         }
                     }
                 }
                 $months = substr($datematch[0], $result['M'], 2);
                 $days = substr($datematch[0], $result['d'], 2);
             } else {
                 $years = 1970;
                 $months = 1;
                 $days = 1;
             }
             if (isset($result['h'])) {
                 $hours = substr($timematch[0], $result['h'], 2);
                 $minutes = substr($timematch[0], $result['m'], 2);
                 $seconds = substr($timematch[0], $result['s'], 2);
             } else {
                 $hours = 0;
                 $minutes = 0;
                 $seconds = 0;
             }
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false);
             break;
         case Zend_Date::RFC_2822:
             $result = preg_match('/\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\s\\+\\d{4}/', $date, $match);
             if (!$result) {
                 throw new Zend_Date_Exception("no RFC 2822 format ({$date})", $date);
             }
             $days = substr($match[0], 5, 2);
             $months = $this->getDigitFromName(substr($match[0], 8, 3));
             $years = substr($match[0], 12, 4);
             $hours = substr($match[0], 17, 2);
             $minutes = substr($match[0], 20, 2);
             $seconds = substr($match[0], 23, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false);
             break;
         case Zend_Date::TIMESTAMP:
             if (is_numeric($date)) {
                 return $this->_assign($calc, $date, $this->getUnixTimestamp());
             }
             throw new Zend_Date_Exception("invalid date ({$date}) operand, timestamp expected", $date);
             break;
             // additional formats
             // break intentionally omitted
         // additional formats
         // break intentionally omitted
         case Zend_Date::ERA:
         case Zend_Date::ERA_NAME:
             throw new Zend_Date_Exception('era not supported', $date);
             break;
         case Zend_Date::DATES:
             try {
                 $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
                 if ($calc == 'set') {
                     --$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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::DATE_FULL:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'full'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format['pattern'], 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc == 'set') {
                     --$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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::DATE_LONG:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'long'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format['pattern'], 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc == 'set') {
                     --$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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::DATE_MEDIUM:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'medium'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format['pattern'], 'format_type' => 'iso', 'locale' => $locale));
                 if ($calc == 'set') {
                     --$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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::DATE_SHORT:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'short'));
                 $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format['pattern'], 'format_type' => 'iso', 'locale' => $locale));
                 if ($parsed['year'] < 100) {
                     $parsed['year'] += 1900;
                     if ($parsed['year'] < 1970) {
                         $parsed['year'] += 100;
                     }
                 }
                 if ($calc == 'set') {
                     --$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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::TIME_FULL:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'full'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format['pattern'], '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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::TIME_LONG:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'long'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format['pattern'], '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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::TIME_MEDIUM:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'medium'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format['pattern'], '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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
         case Zend_Date::TIME_SHORT:
             try {
                 $format = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'short'));
                 $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format['pattern'], '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) {
                 throw new Zend_Date_Exception($e->getMessage(), $date);
             }
             break;
             // ATOM and RFC_3339 are identical
         // ATOM and RFC_3339 are identical
         case Zend_Date::ATOM:
         case Zend_Date::RFC_3339:
             $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) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, ATOM format expected", $date);
             }
             $years = substr($match[0], 0, 4);
             $months = substr($match[0], 5, 2);
             $days = substr($match[0], 8, 2);
             $hours = substr($match[0], 11, 2);
             $minutes = substr($match[0], 14, 2);
             $seconds = substr($match[0], 17, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case Zend_Date::COOKIE:
             $result = preg_match('/\\w{6,9},\\s\\d{2}-\\w{3}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2}\\s\\w{3}/', $date, $match);
             if (!$result) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, COOKIE format expected", $date);
             }
             $match[0] = substr($match[0], strpos($match[0], ' ') + 1);
             $days = substr($match[0], 0, 2);
             $months = $this->getDigitFromName(substr($match[0], 3, 3));
             $years = substr($match[0], 7, 4);
             $years += 2000;
             $hours = substr($match[0], 10, 2);
             $minutes = substr($match[0], 13, 2);
             $seconds = substr($match[0], 16, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case Zend_Date::RFC_822:
             // new RFC 822 format
             $result = preg_match('/^\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{2}\\s\\d{2}:\\d{2}:\\d{2}\\s[+-]{1}\\d{4}$/', $date, $match);
             if (!$result) {
                 // old RFC 822 format
                 $result = preg_match('/\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{2}\\s\\d{2}:\\d{2}:\\d{2}\\s\\w{1,3}/', $date, $match);
             }
             if (!$result) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 822 date format expected", $date);
             }
             $days = substr($match[0], 5, 2);
             $months = $this->getDigitFromName(substr($match[0], 8, 3));
             $years = substr($match[0], 12, 4);
             $years += 2000;
             $hours = substr($match[0], 15, 2);
             $minutes = substr($match[0], 18, 2);
             $seconds = substr($match[0], 21, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, false), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, false), false);
             break;
         case Zend_Date::RFC_850:
             $result = preg_match('/\\w{6,9},\\s\\d{2}-\\w{3}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2}\\s\\w{3}/', $date, $match);
             if (!$result) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 850 date format expected", $date);
             }
             $match[0] = substr($match[0], strpos($match[0], ' ') + 1);
             $days = substr($match[0], 0, 2);
             $months = $this->getDigitFromName(substr($match[0], 3, 3));
             $years = substr($match[0], 7, 4);
             $years += 2000;
             $hours = substr($match[0], 10, 2);
             $minutes = substr($match[0], 13, 2);
             $seconds = substr($match[0], 16, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case Zend_Date::RFC_1036:
             $result = preg_match('/^\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{2}\\s\\d{2}:\\d{2}:\\d{2}\\s[+-]{1}\\d{4}$/', $date, $match);
             if (!$result) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 1036 date format expected", $date);
             }
             $days = substr($match[0], 5, 2);
             $months = $this->getDigitFromName(substr($match[0], 8, 3));
             $years = substr($match[0], 12, 4);
             $years += 2000;
             $hours = substr($match[0], 15, 2);
             $minutes = substr($match[0], 18, 2);
             $seconds = substr($match[0], 21, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case Zend_Date::RFC_1123:
             $result = preg_match('/^\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\s[+-]{1}\\d{4}$/', $date, $match);
             if (!$result) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RFC 1123 date format expected", $date);
             }
             $days = substr($match[0], 5, 2);
             $months = $this->getDigitFromName(substr($match[0], 8, 3));
             $years = substr($match[0], 12, 4);
             $hours = substr($match[0], 17, 2);
             $minutes = substr($match[0], 20, 2);
             $seconds = substr($match[0], 23, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case Zend_Date::RSS:
             $result = preg_match('/^\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\s[+-]{1}\\d{4}$/', $date, $match);
             if (!$result) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, RSS date format expected", $date);
             }
             $days = substr($match[0], 5, 2);
             $months = $this->getDigitFromName(substr($match[0], 8, 3));
             $years = substr($match[0], 12, 4);
             $hours = substr($match[0], 17, 2);
             $minutes = substr($match[0], 20, 2);
             $seconds = substr($match[0], 23, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), false);
             break;
         case Zend_Date::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) {
                 throw new Zend_Date_Exception("invalid date ({$date}) operand, W3C date format expected", $date);
             }
             $years = substr($match[0], 0, 4);
             $months = substr($match[0], 5, 2);
             $days = substr($match[0], 8, 2);
             $hours = substr($match[0], 11, 2);
             $minutes = substr($match[0], 14, 2);
             $seconds = substr($match[0], 17, 2);
             if ($calc == 'set') {
                 --$months;
                 --$month;
                 --$days;
                 --$day;
                 $years -= 1970;
                 $year -= 1970;
             }
             return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1 + $months, 1 + $days, 1970 + $years, 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 ($calc == 'set') {
                         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)) {
                         throw new Zend_Date_Exception($e->getMessage(), $date);
                     }
                 }
             }
             return $this->_assign($calc, $date, $this->getUnixTimestamp(), false);
             break;
     }
 }
 /**
  * Installs the current locale into i18n
  *
  * @param boolean $persist Attempt to persist any detected locale within session / cookies
  */
 public static function install_locale($persist = true)
 {
     // Ensure the locale is set correctly given the designated parameters
     $locale = self::current_locale($persist);
     if (empty($locale)) {
         return;
     }
     i18n::set_locale($locale);
     // LC_NUMERIC causes SQL errors for some locales (comma as decimal indicator) so skip
     foreach (array(LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_TIME) as $category) {
         setlocale($category, "{$locale}.UTF-8", $locale);
     }
     // Get date/time formats from Zend
     require_once 'Zend/Date.php';
     i18n::config()->date_format = Zend_Locale_Format::getDateFormat($locale);
     i18n::config()->time_format = Zend_Locale_Format::getTimeFormat($locale);
 }
Esempio n. 9
0
 /**
  * Returns a representation of a date or datepart
  * This could be for example a localized monthname, the time without date,
  * the era or only the fractional seconds. There are about 50 different supported date parts.
  * For a complete list of supported datepart values look into the docu
  *
  * @param  string              $part    OPTIONAL Part of the date to return, if null the timestamp is returned
  * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
  * @return integer|string  date or datepart
  */
 public function get($part = null, $locale = null)
 {
     if ($locale === null) {
         $locale = $this->getLocale();
     }
     if (Zend_Locale::isLocale($part)) {
         $locale = $part;
         $part = null;
     }
     if ($part === null) {
         $part = Zend_Date::TIMESTAMP;
     }
     if (!defined("self::" . $part)) {
         return $this->toString($part, $locale);
     }
     switch ($part) {
         // day formats
         case Zend_Date::DAY:
             return $this->date('d', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::WEEKDAY_SHORT:
             $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
             $day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday));
             return substr($day[$weekday], 0, 3);
             break;
         case Zend_Date::DAY_SHORT:
             return $this->date('j', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::WEEKDAY:
             $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
             $day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday));
             return $day[$weekday];
             break;
         case Zend_Date::WEEKDAY_8601:
             return $this->date('N', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::DAY_SUFFIX:
             return $this->date('S', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::WEEKDAY_DIGIT:
             return $this->date('w', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::DAY_OF_YEAR:
             return $this->date('z', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::WEEKDAY_NARROW:
             $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
             $day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday));
             return substr($day[$weekday], 0, 1);
             break;
         case Zend_Date::WEEKDAY_NAME:
             $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
             $day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday));
             return $day[$weekday];
             break;
             // week formats
         // week formats
         case Zend_Date::WEEK:
             return $this->date('W', $this->getUnixTimestamp(), false);
             break;
             // month formats
         // month formats
         case Zend_Date::MONTH_NAME:
             $month = $this->date('n', $this->getUnixTimestamp(), false);
             $mon = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'wide', $month));
             return $mon[$month];
             break;
         case Zend_Date::MONTH:
             return $this->date('m', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::MONTH_NAME_SHORT:
             $month = $this->date('n', $this->getUnixTimestamp(), false);
             $mon = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month));
             return $mon[$month];
             break;
         case Zend_Date::MONTH_SHORT:
             return $this->date('n', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::MONTH_DAYS:
             return $this->date('t', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::MONTH_NAME_NARROW:
             $month = $this->date('n', $this->getUnixTimestamp(), false);
             $mon = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month));
             return substr($mon[$month], 0, 1);
             break;
             // year formats
         // year formats
         case Zend_Date::LEAPYEAR:
             return $this->date('L', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::YEAR_8601:
             return $this->date('o', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::YEAR:
             return $this->date('Y', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::YEAR_SHORT:
             return $this->date('y', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::YEAR_SHORT_8601:
             $year = $this->date('o', $this->getUnixTimestamp(), false);
             return substr($year, -2);
             break;
             // time formats
         // time formats
         case Zend_Date::MERIDIEM:
             $am = $this->date('a', $this->getUnixTimestamp(), false);
             $amlocal = Zend_Locale_Data::getContent($locale, 'daytime', 'gregorian');
             return $amlocal[$am];
             break;
         case Zend_Date::SWATCH:
             return $this->date('B', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::HOUR_SHORT_AM:
             return $this->date('g', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::HOUR_SHORT:
             return $this->date('G', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::HOUR_AM:
             return $this->date('h', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::HOUR:
             return $this->date('H', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::MINUTE:
             return $this->date('i', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::SECOND:
             return $this->date('s', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::MINUTE_SHORT:
             return $this->date('i', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::SECOND_SHORT:
             return $this->date('s', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::MILLISECOND:
             return $this->_Fractional;
             break;
             // timezone formats
         // timezone formats
         case Zend_Date::TIMEZONE_NAME:
             return $this->date('e', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::DAYLIGHT:
             return $this->date('I', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::GMT_DIFF:
             return $this->date('O', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::GMT_DIFF_SEP:
             return $this->date('P', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::TIMEZONE:
             return $this->date('T', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::TIMEZONE_SECS:
             return $this->date('Z', $this->getUnixTimestamp(), false);
             break;
             // date strings
         // date strings
         case Zend_Date::ISO_8601:
             return $this->date('c', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::RFC_2822:
             return $this->date('r', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::TIMESTAMP:
             return $this->getUnixTimestamp();
             break;
             // additional formats
         // additional formats
         case Zend_Date::ERA:
             $year = $this->date('Y', $this->getUnixTimestamp(), false);
             if ($year < 0) {
                 $era = Zend_Locale_Data::getContent($locale, 'erashort', array('gregorian', '0'));
                 return $era['0'];
             }
             $era = Zend_Locale_Data::getContent($locale, 'erashort', array('gregorian', '1'));
             return $era['1'];
             break;
         case Zend_Date::ERA_NAME:
             $year = $this->date('Y', $this->getUnixTimestamp(), false);
             if ($year < 0) {
                 $era = Zend_Locale_Data::getContent($locale, 'era', array('gregorian', '0'));
                 return $era['0'];
             }
             $era = Zend_Locale_Data::getContent($locale, 'era', array('gregorian', '1'));
             if (!isset($era['1'])) {
                 return false;
             }
             return $era['1'];
             break;
         case Zend_Date::DATES:
             return $this->toString(Zend_Locale_Format::getDateFormat($locale), 'iso', $locale);
             break;
         case Zend_Date::DATE_FULL:
             $date = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'full'));
             return $this->toString($date['pattern'], 'iso', $locale);
             break;
         case Zend_Date::DATE_LONG:
             $date = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'long'));
             return $this->toString($date['pattern'], 'iso', $locale);
             break;
         case Zend_Date::DATE_MEDIUM:
             $date = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'medium'));
             return $this->toString($date['pattern'], 'iso', $locale);
             break;
         case Zend_Date::DATE_SHORT:
             $date = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'short'));
             return $this->toString($date['pattern'], 'iso', $locale);
             break;
         case Zend_Date::TIMES:
             return $this->toString(Zend_Locale_Format::getTimeFormat($locale), 'iso', $locale);
             break;
         case Zend_Date::TIME_FULL:
             $time = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'full'));
             return $this->toString($time['pattern'], 'iso', $locale);
             break;
         case Zend_Date::TIME_LONG:
             $time = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'long'));
             return $this->toString($time['pattern'], 'iso', $locale);
             break;
         case Zend_Date::TIME_MEDIUM:
             $time = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'medium'));
             return $this->toString($time['pattern'], 'iso', $locale);
             break;
         case Zend_Date::TIME_SHORT:
             $time = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'short'));
             return $this->toString($time['pattern'], 'iso', $locale);
             break;
         case Zend_Date::ATOM:
             return $this->date('Y\\-m\\-d\\TH\\:i\\:sP', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::COOKIE:
             return $this->date('l\\, d\\-M\\-y H\\:i\\:s e', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::RFC_822:
             return $this->date('D\\, d M y H\\:i\\:s O', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::RFC_850:
             return $this->date('l\\, d\\-M\\-y H\\:i\\:s e', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::RFC_1036:
             return $this->date('D\\, d M y H\\:i\\:s O', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::RFC_1123:
             return $this->date('D\\, d M Y H\\:i\\:s O', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::RFC_3339:
             return $this->date('Y\\-m\\-d\\TH\\:i\\:sP', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::RSS:
             return $this->date('D\\, d M Y H\\:i\\:s O', $this->getUnixTimestamp(), false);
             break;
         case Zend_Date::W3C:
             return $this->date('Y\\-m\\-d\\TH\\:i\\:sP', $this->getUnixTimestamp(), false);
             break;
     }
 }
 /**
  * convert date to string
  * 
  * @param Tinebase_DateTime $date [optional]
  * @param string            $timezone [optional]
  * @param Zend_Locale       $locale [optional]
  * @param string            $part one of date, time or datetime [optional]
  * @param boolean           $addWeekday should the weekday be added (only works with $part = 'date[time]') [optional] 
  * @return string
  */
 public static function dateToStringInTzAndLocaleFormat(DateTime $date = null, $timezone = null, Zend_Locale $locale = null, $part = 'datetime', $addWeekday = false)
 {
     $date = $date !== null ? clone $date : Tinebase_DateTime::now();
     $timezone = $timezone !== null ? $timezone : Tinebase_Core::getUserTimezone();
     $locale = $locale !== null ? $locale : Tinebase_Core::get(Tinebase_Core::LOCALE);
     $date = new Zend_Date($date->getTimestamp());
     $date->setTimezone($timezone);
     if (in_array($part, array('date', 'time', 'datetime'))) {
         $dateString = $date->toString(Zend_Locale_Format::getDateFormat($locale), $locale);
         if ($addWeekday) {
             $dateString = $date->toString('EEEE', $locale) . ', ' . $dateString;
         }
         $timeString = $date->toString(Zend_Locale_Format::getTimeFormat($locale), $locale);
         switch ($part) {
             case 'date':
                 return $dateString;
             case 'time':
                 return $timeString;
             default:
                 return $dateString . ' ' . $timeString;
         }
     } else {
         return $date->toString($part, $locale);
     }
 }
Esempio n. 11
0
 /**
  * Reads a localized value, normalizes and returns it.
  * Returns an empty string if no value is passed.
  * @param mixed $value
  * @param string $type (boolean|date|time|integer|float|decimal|currency)
  * @return mixed
  */
 private function _normalize($value, $type, $num_of_decimals)
 {
     if (strlen($value) == 0) {
         return '';
     }
     switch ($type) {
         case 'boolean':
             $yes_no = Zend_Locale_Data::getContent($this->_locale_engine, 'questionstrings');
             $yes_regexp = '/^(' . str_replace(':', '|', $yes_no['yes']) . ')$/i';
             if (preg_match($yes_regexp, $value)) {
                 return 1;
             }
             return 0;
         case 'date':
             $date = Zend_Locale_Format::getDate($value, array('locale' => $this->_locale_engine, 'fix_date' => true));
             $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
             $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
             return "{$date['year']}-{$date['month']}-{$date['day']}";
         case 'time':
             $date_format = Zend_Locale_Format::getTimeFormat($this->_locale_engine);
             $date = Zend_Locale_Format::getDate($value, array('date_format' => $date_format, 'locale' => $this->_locale_engine));
             if (!isset($date['hour'])) {
                 $date['hour'] = '00';
             }
             if (!isset($date['minute'])) {
                 $date['minute'] = '00';
             }
             if (!isset($date['second'])) {
                 $date['second'] = '00';
             }
             return "{$date['hour']}:{$date['minute']}:{$date['second']}";
         case 'datetime':
             $date = Zend_Locale_Format::getDateTime($value, array('locale' => $this->_locale_engine, 'fix_date' => true));
             $date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
             $date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
             $date['hour'] = str_pad($date['hour'], 2, 0, STR_PAD_LEFT);
             $date['minute'] = str_pad($date['minute'], 2, 0, STR_PAD_LEFT);
             $date['second'] = str_pad($date['second'], 2, 0, STR_PAD_LEFT);
             return "{$date['year']}-{$date['month']}-{$date['day']} {$date['hour']}:{$date['minute']}:{$date['second']}";
             break;
         case 'integer':
             return Zend_Locale_Format::getInteger($value, array('locale' => $this->_locale_engine));
         case 'float':
             if ($num_of_decimals === null) {
                 $num_of_decimals = 3;
             }
             return Zend_Locale_Format::getFloat($value, array('precision' => $num_of_decimals, 'locale' => $this->_locale_engine));
         case 'decimal':
             if ($num_of_decimals === null) {
                 $num_of_decimals = 2;
             }
             return Zend_Locale_Format::getFloat($value, array('precision' => $num_of_decimals, 'locale' => $this->_locale_engine));
     }
     return $value;
 }
Esempio n. 12
0
 /**
  * @return string ISO time format
  */
 public static function get_time_format()
 {
     require_once 'Zend/Date.php';
     $timeFormat = Config::inst()->get('i18n', 'time_format');
     return $timeFormat ? $timeFormat : Zend_Locale_Format::getTimeFormat(self::get_locale());
 }
Esempio n. 13
0
 /**
  * convert date to string
  * 
  * @param Tinebase_DateTime $_date [optional]
  * @param string            $_timezone [optional]
  * @param Zend_Locale       $_locale [optional]
  * @param string            $_part one of date, time or datetime
  * @return string
  */
 public static function dateToStringInTzAndLocaleFormat(DateTime $_date = NULL, $_timezone = NULL, Zend_Locale $_locale = NULL, $_part = 'datetime')
 {
     $date = $_date !== NULL ? clone $_date : Tinebase_DateTime::now();
     $timezone = $_timezone !== NULL ? $_timezone : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
     $locale = $_locale !== NULL ? $_locale : Tinebase_Core::get(Tinebase_Core::LOCALE);
     $date = new Zend_Date($date->getTimestamp());
     $date->setTimezone($timezone);
     $dateString = $date->toString(Zend_Locale_Format::getDateFormat($locale), $locale);
     $timeString = $date->toString(Zend_Locale_Format::getTimeFormat($locale), $locale);
     switch ($_part) {
         case 'date':
             return $dateString;
         case 'time':
             return $timeString;
         default:
             return $dateString . ' ' . $timeString;
     }
 }