Beispiel #1
0
 /**
  * Returns an array with translated yes strings
  *
  * @param  string|Zend_Locale $locale (Optional) Locale for language translation (defaults to $this locale)
  * @return array
  */
 public static function getQuestion($locale = null)
 {
     $locale = self::findLocale($locale);
     $quest = Data::getList($locale, 'question');
     $yes = explode(':', $quest['yes']);
     $no = explode(':', $quest['no']);
     $quest['yes'] = $yes[0];
     $quest['yesarray'] = $yes;
     $quest['no'] = $no[0];
     $quest['noarray'] = $no;
     $quest['yesexpr'] = self::_prepareQuestionString($yes);
     $quest['noexpr'] = self::_prepareQuestionString($no);
     return $quest;
 }
Beispiel #2
0
 private static function _parseDate($date, $options)
 {
     if (!self::_getUniCodeSupport()) {
         trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE);
     }
     $options = self::_checkOptions($options) + self::$_options;
     $test = array('h', 'H', 'm', 's', 'y', 'Y', 'M', 'd', 'D', 'E', 'S', 'l', 'B', 'I', 'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v');
     $format = $options['date_format'];
     $number = $date;
     // working copy
     $result['date_format'] = $format;
     // save the format used to normalize $number (convenience)
     $result['locale'] = $options['locale'];
     // save the locale used to normalize $number (convenience)
     $oenc = iconv_get_encoding('internal_encoding');
     //iconv_set_encoding('internal_encoding', 'UTF-8');
     $day = iconv_strpos($format, 'd');
     $month = iconv_strpos($format, 'M');
     $year = iconv_strpos($format, 'y');
     $hour = iconv_strpos($format, 'H');
     $min = iconv_strpos($format, 'm');
     $sec = iconv_strpos($format, 's');
     $am = null;
     if ($hour === false) {
         $hour = iconv_strpos($format, 'h');
     }
     if ($year === false) {
         $year = iconv_strpos($format, 'Y');
     }
     if ($day === false) {
         $day = iconv_strpos($format, 'E');
         if ($day === false) {
             $day = iconv_strpos($format, 'D');
         }
     }
     if ($day !== false) {
         $parse[$day] = 'd';
         if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) {
             // erase day string
             $daylist = Data::getList($options['locale'], 'day');
             foreach ($daylist as $key => $name) {
                 if (iconv_strpos($number, $name) !== false) {
                     $number = str_replace($name, "EEEE", $number);
                     break;
                 }
             }
         }
     }
     $position = false;
     if ($month !== false) {
         $parse[$month] = 'M';
         if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) {
             // prepare to convert month name to their numeric equivalents, if requested,
             // and we have a $options['locale']
             $position = self::_replaceMonth($number, Data::getList($options['locale'], 'month'));
             if ($position === false) {
                 $position = self::_replaceMonth($number, Data::getList($options['locale'], 'month', array('gregorian', 'format', 'abbreviated')));
             }
         }
     }
     if ($year !== false) {
         $parse[$year] = 'y';
     }
     if ($hour !== false) {
         $parse[$hour] = 'H';
     }
     if ($min !== false) {
         $parse[$min] = 'm';
     }
     if ($sec !== false) {
         $parse[$sec] = 's';
     }
     if (empty($parse)) {
         iconv_set_encoding('internal_encoding', $oenc);
         throw new Exception("Unknown date format, neither date nor time in '" . $format . "' found");
     }
     ksort($parse);
     // get daytime
     if (iconv_strpos($format, 'a') !== false) {
         if (iconv_strpos(strtoupper($number), strtoupper(Data::getContent($options['locale'], 'am'))) !== false) {
             $am = true;
         } else {
             if (iconv_strpos(strtoupper($number), strtoupper(Data::getContent($options['locale'], 'pm'))) !== false) {
                 $am = false;
             }
         }
     }
     // split number parts
     $split = false;
     preg_match_all('/\\d+/u', $number, $splitted);
     if (count($splitted[0]) == 0) {
         iconv_set_encoding('internal_encoding', $oenc);
         //throw new Exception("No date part in '$date' found.");
     }
     if (count($splitted[0]) == 1) {
         $split = 0;
     }
     $cnt = 0;
     foreach ($parse as $key => $value) {
         switch ($value) {
             case 'd':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['day'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['day'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'M':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['month'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['month'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'y':
                 $length = 2;
                 if (iconv_substr($format, $year, 4) == 'yyyy' || iconv_substr($format, $year, 4) == 'YYYY') {
                     $length = 4;
                 }
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['year'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['year'] = iconv_substr($splitted[0][0], $split, $length);
                     $split += $length;
                 }
                 ++$cnt;
                 break;
             case 'H':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['hour'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['hour'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'm':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['minute'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['minute'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 's':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['second'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['second'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
         }
     }
     // AM/PM correction
     if ($hour !== false) {
         if ($am === true and $result['hour'] == 12) {
             $result['hour'] = 0;
         } else {
             if ($am === false and $result['hour'] != 12) {
                 $result['hour'] += 12;
             }
         }
     }
     if ($options['fix_date'] === true) {
         $result['fixed'] = 0;
         // nothing has been "fixed" by swapping date parts around (yet)
     }
     if ($day !== false) {
         // fix false month
         if (isset($result['day']) and isset($result['month'])) {
             if ($position !== false and (iconv_strpos($date, $result['day']) === false or isset($result['year']) and iconv_strpos($date, $result['year']) === false)) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     //throw new Exception("Unable to parse date '$date' using '" . $format . "' (false month, $position, $month)");
                 }
                 $temp = $result['day'];
                 $result['day'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 1;
             }
         }
         // fix switched values d <> y
         if (isset($result['day']) and isset($result['year'])) {
             if ($result['day'] > 31) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     //throw new Exception("Unable to parse date '$date' using '" . $format . "' (d <> y)");
                 }
                 $temp = $result['year'];
                 $result['year'] = $result['day'];
                 $result['day'] = $temp;
                 $result['fixed'] = 2;
             }
         }
         // fix switched values M <> y
         if (isset($result['month']) and isset($result['year'])) {
             if ($result['month'] > 31) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     //throw new Exception("Unable to parse date '$date' using '" . $format . "' (M <> y)");
                 }
                 $temp = $result['year'];
                 $result['year'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 3;
             }
         }
         // fix switched values M <> d
         if (isset($result['month']) and isset($result['day'])) {
             if ($result['month'] > 12) {
                 if ($options['fix_date'] !== true || $result['month'] > 31) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     //throw new Exception("Unable to parse date '$date' using '" . $format . "' (M <> d)");
                 }
                 $temp = $result['day'];
                 $result['day'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 4;
             }
         }
     }
     if (isset($result['year'])) {
         if (iconv_strlen($result['year']) == 2 && $result['year'] < 10 || (iconv_strpos($format, 'yy') !== false && iconv_strpos($format, 'yyyy') === false || iconv_strpos($format, 'YY') !== false && iconv_strpos($format, 'YYYY') === false)) {
             if ($result['year'] >= 0 && $result['year'] < 100) {
                 if ($result['year'] < 70) {
                     $result['year'] = (int) $result['year'] + 100;
                 }
                 $result['year'] = (int) $result['year'] + 1900;
             }
         }
     }
     //iconv_set_encoding('internal_encoding', $oenc);
     return $result;
 }