Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Data Fields | Static Protected Member Functions
Zend_Locale_Format Class Reference

Static Public Member Functions

static setOptions (array $options=array())
 
static convertNumerals ($input, $from, $to=null)
 
static getNumber ($input, array $options=array())
 
static toNumber ($value, array $options=array())
 
static isNumber ($input, array $options=array())
 
static getFloat ($input, array $options=array())
 
static toFloat ($value, array $options=array())
 
static isFloat ($value, array $options=array())
 
static getInteger ($input, array $options=array())
 
static toInteger ($value, array $options=array())
 
static isInteger ($value, array $options=array())
 
static convertPhpToIsoFormat ($format)
 
static getDateFormat ($locale=null)
 
static getDate ($date, array $options=array())
 
static checkDateFormat ($date, array $options=array())
 
static getTimeFormat ($locale=null)
 
static getTime ($time, array $options=array())
 
static getDateTimeFormat ($locale=null)
 
static getDateTime ($datetime, array $options=array())
 

Data Fields

const STANDARD = 'auto'
 

Static Protected Member Functions

static _replaceMonth (&$number, $monthlist)
 
static _getUniCodeSupport ()
 
static _getEncoding ()
 
static _setEncoding ($encoding)
 

Detailed Description

Definition at line 35 of file Format.php.

Member Function Documentation

◆ _getEncoding()

static _getEncoding ( )
staticprotected

Internal method to retrieve the current encoding via the ini setting default_charset for PHP >= 5.6 or iconv_get_encoding otherwise.

Returns
string

Definition at line 1318 of file Format.php.

1319  {
1320  $oenc = PHP_VERSION_ID < 50600
1321  ? iconv_get_encoding('internal_encoding')
1322  : ini_get('default_charset');
1323 
1324  return $oenc;
1325  }

◆ _getUniCodeSupport()

static _getUniCodeSupport ( )
staticprotected

Internal method to detect of Unicode supports UTF8 which should be enabled within vanilla php installations

Returns
boolean

Definition at line 1307 of file Format.php.

1308  {
1309  return (@preg_match('/\pL/u', 'a')) ? true : false;
1310  }

◆ _replaceMonth()

static _replaceMonth ( $number,
  $monthlist 
)
staticprotected

Search $number for a month name found in $monthlist, and replace if found.

Parameters
string$numberDate string (modified)
array$monthlistList of month names
Returns
int|false Position of replaced string (false if nothing replaced)

Definition at line 1104 of file Format.php.

1105  {
1106  // If $locale was invalid, $monthlist will default to a "root" identity
1107  // mapping for each month number from 1 to 12.
1108  // If no $locale was given, or $locale was invalid, do not use this identity mapping to normalize.
1109  // Otherwise, translate locale aware month names in $number to their numeric equivalents.
1110  $position = false;
1111  if ($monthlist && $monthlist[1] != 1) {
1112  foreach($monthlist as $key => $name) {
1113  if (($position = iconv_strpos($number, $name, 0, 'UTF-8')) !== false) {
1114  $number = str_ireplace($name, $key, $number);
1115  return $position;
1116  }
1117  }
1118  }
1119 
1120  return false;
1121  }
$number
Definition: details.phtml:22
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _setEncoding()

static _setEncoding (   $encoding)
staticprotected

Internal method to set the encoding via the ini setting default_charset for PHP >= 5.6 or iconv_set_encoding otherwise.

Parameters
string$encoding
Returns
void

Definition at line 1334 of file Format.php.

1335  {
1336  if (PHP_VERSION_ID < 50600) {
1337  iconv_set_encoding('internal_encoding', $encoding);
1338  } else {
1339  ini_set('default_charset', $encoding);
1340  }
1341  }
ini_set($varName, $newValue)

◆ checkDateFormat()

static checkDateFormat (   $date,
array  $options = array() 
)
static

Returns if the given datestring contains all date parts from the given format. If no format is given, the default date format from the locale is used If you want to check if the date is a proper date you should use Zend_Date::isDate()

Parameters
string$dateDate string
array$optionsOptions: format_type, fix_date, locale, date_format. See setOptions() for details.
Returns
boolean

Definition at line 1174 of file Format.php.

1175  {
1176  try {
1177  $date = self::getDate($date, $options);
1178  } catch (Exception $e) {
1179  return false;
1180  }
1181 
1182  if (empty($options['date_format'])) {
1183  $options['format_type'] = 'iso';
1184  $options['date_format'] = self::getDateFormat(isset($options['locale']) ? $options['locale'] : null);
1185  }
1186  $options = self::_checkOptions($options) + self::$_options;
1187 
1188  // day expected but not parsed
1189  if ((iconv_strpos($options['date_format'], 'd', 0, 'UTF-8') !== false) and (!isset($date['day']) or ($date['day'] === ""))) {
1190  return false;
1191  }
1192 
1193  // month expected but not parsed
1194  if ((iconv_strpos($options['date_format'], 'M', 0, 'UTF-8') !== false) and (!isset($date['month']) or ($date['month'] === ""))) {
1195  return false;
1196  }
1197 
1198  // year expected but not parsed
1199  if (((iconv_strpos($options['date_format'], 'Y', 0, 'UTF-8') !== false) or
1200  (iconv_strpos($options['date_format'], 'y', 0, 'UTF-8') !== false)) and (!isset($date['year']) or ($date['year'] === ""))) {
1201  return false;
1202  }
1203 
1204  // second expected but not parsed
1205  if ((iconv_strpos($options['date_format'], 's', 0, 'UTF-8') !== false) and (!isset($date['second']) or ($date['second'] === ""))) {
1206  return false;
1207  }
1208 
1209  // minute expected but not parsed
1210  if ((iconv_strpos($options['date_format'], 'm', 0, 'UTF-8') !== false) and (!isset($date['minute']) or ($date['minute'] === ""))) {
1211  return false;
1212  }
1213 
1214  // hour expected but not parsed
1215  if (((iconv_strpos($options['date_format'], 'H', 0, 'UTF-8') !== false) or
1216  (iconv_strpos($options['date_format'], 'h', 0, 'UTF-8') !== false)) and (!isset($date['hour']) or ($date['hour'] === ""))) {
1217  return false;
1218  }
1219 
1220  return true;
1221  }
static getDate($date, array $options=array())
Definition: Format.php:1154
static getDateFormat($locale=null)
Definition: Format.php:1130

◆ convertNumerals()

static convertNumerals (   $input,
  $from,
  $to = null 
)
static

Changes the numbers/digits within a given string from one script to another 'Decimal' representated the stardard numbers 0-9, if a script does not exist an exception will be thrown.

Examples for conversion from Arabic to Latin numerals: convertNumerals('١١٠ Tests', 'Arab'); -> returns '100 Tests' Example for conversion from Latin to Arabic numerals: convertNumerals('100 Tests', 'Latn', 'Arab'); -> returns '١١٠ Tests'

Parameters
string$inputString to convert
string$fromScript to parse, see Zend_Locale::getScriptList() for details.
string$toOPTIONAL Script to convert to
Returns
string Returns the converted input
Exceptions
Zend_Locale_Exception

Definition at line 198 of file Format.php.

199  {
200  if (!self::_getUniCodeSupport()) {
201  trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE);
202  }
203 
204  $from = strtolower($from);
205  $source = Zend_Locale_Data::getContent('en', 'numberingsystem', $from);
206  if (empty($source)) {
207  #require_once 'Zend/Locale/Exception.php';
208  throw new Zend_Locale_Exception("Unknown script '$from'. Use 'Latn' for digits 0,1,2,3,4,5,6,7,8,9.");
209  }
210 
211  if ($to !== null) {
212  $to = strtolower($to);
213  $target = Zend_Locale_Data::getContent('en', 'numberingsystem', $to);
214  if (empty($target)) {
215  #require_once 'Zend/Locale/Exception.php';
216  throw new Zend_Locale_Exception("Unknown script '$to'. Use 'Latn' for digits 0,1,2,3,4,5,6,7,8,9.");
217  }
218  } else {
219  $target = '0123456789';
220  }
221 
222  for ($x = 0; $x < 10; ++$x) {
223  $asource[$x] = "/" . iconv_substr($source, $x, 1, 'UTF-8') . "/u";
224  $atarget[$x] = iconv_substr($target, $x, 1, 'UTF-8');
225  }
226 
227  return preg_replace($asource, $atarget, $input);
228  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$source
Definition: source.php:23
$target
Definition: skip.phtml:8

◆ convertPhpToIsoFormat()

static convertPhpToIsoFormat (   $format)
static

Converts a format string from PHP's date format to ISO format Remember that Zend Date always returns localized string, so a month name which returns the english month in php's date() will return the translated month name with this function... use 'en' as locale if you are in need of the original english names

The conversion has the following restrictions: 'a', 'A' - Meridiem is not explicit upper/lowercase, you have to upper/lowercase the translated value yourself

Parameters
string$formatFormat string in PHP's date format
Returns
string Format string in ISO format

Definition at line 746 of file Format.php.

747  {
748  if ($format === null) {
749  return null;
750  }
751 
752  $convert = array(
753  'd' => 'dd' , 'D' => 'EE' , 'j' => 'd' , 'l' => 'EEEE',
754  'N' => 'eee' , 'S' => 'SS' , 'w' => 'e' , 'z' => 'D' ,
755  'W' => 'ww' , 'F' => 'MMMM', 'm' => 'MM' , 'M' => 'MMM' ,
756  'n' => 'M' , 't' => 'ddd' , 'L' => 'l' , 'o' => 'YYYY',
757  'Y' => 'yyyy', 'y' => 'yy' , 'a' => 'a' , 'A' => 'a' ,
758  'B' => 'B' , 'g' => 'h' , 'G' => 'H' , 'h' => 'hh' ,
759  'H' => 'HH' , 'i' => 'mm' , 's' => 'ss' , 'e' => 'zzzz',
760  'I' => 'I' , 'O' => 'Z' , 'P' => 'ZZZZ', 'T' => 'z' ,
761  'Z' => 'X' , 'c' => 'yyyy-MM-ddTHH:mm:ssZZZZ', 'r' => 'r',
762  'U' => 'U',
763  );
764  $escaped = false;
765  $inEscapedString = false;
766  $converted = array();
767  foreach (str_split($format) as $char) {
768  if (!$escaped && $char == '\\') {
769  // Next char will be escaped: let's remember it
770  $escaped = true;
771  } elseif ($escaped) {
772  if (!$inEscapedString) {
773  // First escaped string: start the quoted chunk
774  $converted[] = "'";
775  $inEscapedString = true;
776  }
777  // Since the previous char was a \ and we are in the quoted
778  // chunk, let's simply add $char as it is
779  $converted[] = $char;
780  $escaped = false;
781  } elseif ($char == "'") {
782  // Single quotes need to be escaped like this
783  $converted[] = "''";
784  } else {
785  if ($inEscapedString) {
786  // Close the single-quoted chunk
787  $converted[] = "'";
788  $inEscapedString = false;
789  }
790  // Convert the unescaped char if needed
791  if (isset($convert[$char])) {
792  $converted[] = $convert[$char];
793  } else {
794  $converted[] = $char;
795  }
796  }
797  }
798 
799  return implode($converted);
800  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$format
Definition: list.phtml:12

◆ getDate()

static getDate (   $date,
array  $options = array() 
)
static

Returns an array with the normalized date from an locale date a input of 10.01.2006 without a $locale would return: array ('day' => 10, 'month' => 1, 'year' => 2006) The 'locale' option is only used to convert human readable day and month names to their numeric equivalents. The 'format' option allows specification of self-defined date formats, when not using the default format for the 'locale'.

Parameters
string$dateDate string
array$optionsOptions: format_type, fix_date, locale, date_format. See setOptions() for details.
Returns
array Possible array members: day, month, year, hour, minute, second, fixed, format

Definition at line 1154 of file Format.php.

1155  {
1156  $options = self::_checkOptions($options) + self::$_options;
1157  if (empty($options['date_format'])) {
1158  $options['format_type'] = 'iso';
1159  $options['date_format'] = self::getDateFormat($options['locale']);
1160  }
1161 
1162  return self::_parseDate($date, $options);
1163  }
static getDateFormat($locale=null)
Definition: Format.php:1130

◆ getDateFormat()

static getDateFormat (   $locale = null)
static

Returns the default date format for $locale.

Parameters
string | Zend_Locale$localeOPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
Returns
string format
Exceptions
Zend_Locale_Exceptionthrows an exception when locale data is broken

Definition at line 1130 of file Format.php.

1131  {
1132  $format = Zend_Locale_Data::getContent($locale, 'date');
1133  if (empty($format)) {
1134  #require_once 'Zend/Locale/Exception.php';
1135  throw new Zend_Locale_Exception("failed to receive data from locale $locale");
1136  }
1137 
1138  return $format;
1139  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$format
Definition: list.phtml:12

◆ getDateTime()

static getDateTime (   $datetime,
array  $options = array() 
)
static

Returns an array with 'year', 'month', 'day', 'hour', 'minute', and 'second' elements extracted from $datetime according to the order described in $format. For a format of 'd.M.y H:i:s', and an input of 10.05.1985 11:20:55, getDateTime() would return: array ('year' => 1985, 'month' => 5, 'day' => 10, 'hour' => 11, 'minute' => 20, 'second' => 55) The optional $locale parameter may be used to help extract times from strings containing both a time and a day or month name.

Parameters
string$datetimeDateTime string
array$optionsOptions: format_type, fix_date, locale, date_format. See setOptions() for details.
Returns
array Possible array members: day, month, year, hour, minute, second, fixed, format

Definition at line 1291 of file Format.php.

1292  {
1293  $options = self::_checkOptions($options) + self::$_options;
1294  if (empty($options['date_format'])) {
1295  $options['format_type'] = 'iso';
1296  $options['date_format'] = self::getDateTimeFormat($options['locale']);
1297  }
1298  return self::_parseDate($datetime, $options);
1299  }
static getDateTimeFormat($locale=null)
Definition: Format.php:1269

◆ getDateTimeFormat()

static getDateTimeFormat (   $locale = null)
static

Returns the default datetime format for $locale.

Parameters
string | Zend_Locale$localeOPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
Returns
string format
Exceptions
Zend_Locale_Exception

Definition at line 1269 of file Format.php.

1270  {
1271  $format = Zend_Locale_Data::getContent($locale, 'datetime');
1272  if (empty($format)) {
1273  #require_once 'Zend/Locale/Exception.php';
1274  throw new Zend_Locale_Exception("failed to receive data from locale $locale");
1275  }
1276  return $format;
1277  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$format
Definition: list.phtml:12

◆ getFloat()

static getFloat (   $input,
array  $options = array() 
)
static

Alias for getNumber

Parameters
string$inputNumber to localize
array$optionsOptions: locale, precision. See setOptions() for details.
Returns
float

Definition at line 646 of file Format.php.

647  {
648  return floatval(self::getNumber($input, $options));
649  }

◆ getInteger()

static getInteger (   $input,
array  $options = array() 
)
static

Returns the first found integer from an string Parsing depends on given locale (grouping and decimal)

Examples for input: ' 2345.4356,1234' = 23455456 '+23,3452.123' = 233452 ' 12343 ' = 12343 '-9456km' = -9456 '0' = 0 '(-){0,1}(\d+(.){0,1})*(\,){0,1})\d+'

Parameters
string$inputInput string to parse for numbers
array$optionsOptions: locale. See setOptions() for details.
Returns
integer Returns the extracted number

Definition at line 694 of file Format.php.

695  {
696  $options['precision'] = 0;
697  return intval(self::getFloat($input, $options));
698  }

◆ getNumber()

static getNumber (   $input,
array  $options = array() 
)
static

Returns the normalized number from a localized one Parsing depends on given locale (grouping and decimal)

Examples for input: '2345.4356,1234' = 23455456.1234 '+23,3452.123' = 233452.123 '12343 ' = 12343 '-9456' = -9456 '0' = 0

Parameters
string$inputInput string to parse for numbers
array$optionsOptions: locale, precision. See setOptions() for details.
Returns
string Returns the extracted number
Exceptions
Zend_Locale_Exception

Definition at line 246 of file Format.php.

247  {
248  $options = self::_checkOptions($options) + self::$_options;
249  if (!is_string($input)) {
250  return $input;
251  }
252 
253  if (!self::isNumber($input, $options)) {
254  #require_once 'Zend/Locale/Exception.php';
255  throw new Zend_Locale_Exception('No localized value in ' . $input . ' found, or the given number does not match the localized format');
256  }
257 
258  // Get correct signs for this locale
259  $symbols = Zend_Locale_Data::getList($options['locale'],'symbols');
260  // Change locale input to be default number
261  if (($input[0] == $symbols['minus']) && ('-' != $input[0])) {
262  $input = '-' . substr($input, 1);
263  }
264 
265  $input = str_replace($symbols['group'],'', $input);
266  if (strpos($input, $symbols['decimal']) !== false) {
267  if ($symbols['decimal'] != '.') {
268  $input = str_replace($symbols['decimal'], ".", $input);
269  }
270 
271  $pre = substr($input, strpos($input, '.') + 1);
272  if ($options['precision'] === null) {
273  $options['precision'] = strlen($pre);
274  }
275 
276  if (strlen($pre) >= $options['precision']) {
277  $input = substr($input, 0, strlen($input) - strlen($pre) + $options['precision']);
278  }
279 
280  if (($options['precision'] == 0) && ($input[strlen($input) - 1] == '.')) {
281  $input = substr($input, 0, -1);
282  }
283  }
284 
285  return $input;
286  }
static getList($locale, $path, $value=false)
Definition: Data.php:318

◆ getTime()

static getTime (   $time,
array  $options = array() 
)
static

Returns an array with 'hour', 'minute', and 'second' elements extracted from $time according to the order described in $format. For a format of 'H:i:s', and an input of 11:20:55, getTime() would return: array ('hour' => 11, 'minute' => 20, 'second' => 55) The optional $locale parameter may be used to help extract times from strings containing both a time and a day or month name.

Parameters
string$timeTime string
array$optionsOptions: format_type, fix_date, locale, date_format. See setOptions() for details.
Returns
array Possible array members: day, month, year, hour, minute, second, fixed, format

Definition at line 1252 of file Format.php.

1253  {
1254  $options = self::_checkOptions($options) + self::$_options;
1255  if (empty($options['date_format'])) {
1256  $options['format_type'] = 'iso';
1257  $options['date_format'] = self::getTimeFormat($options['locale']);
1258  }
1259  return self::_parseDate($time, $options);
1260  }
static getTimeFormat($locale=null)
Definition: Format.php:1230

◆ getTimeFormat()

static getTimeFormat (   $locale = null)
static

Returns the default time format for $locale.

Parameters
string | Zend_Locale$localeOPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
Returns
string format
Exceptions
Zend_Locale_Exception

Definition at line 1230 of file Format.php.

1231  {
1232  $format = Zend_Locale_Data::getContent($locale, 'time');
1233  if (empty($format)) {
1234  #require_once 'Zend/Locale/Exception.php';
1235  throw new Zend_Locale_Exception("failed to receive data from locale $locale");
1236  }
1237  return $format;
1238  }
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$format
Definition: list.phtml:12

◆ isFloat()

static isFloat (   $value,
array  $options = array() 
)
static

Returns if a float was found Alias for isNumber()

Parameters
string$valueLocalized number string
array$optionsOptions: locale. See setOptions() for details.
Returns
boolean Returns true if a number was found

Definition at line 673 of file Format.php.

674  {
675  return self::isNumber($value, $options);
676  }
static isNumber($input, array $options=array())
Definition: Format.php:510
$value
Definition: gender.phtml:16

◆ isInteger()

static isInteger (   $value,
array  $options = array() 
)
static

Returns if a integer was found

Parameters
string$valueLocalized number string
array$optionsOptions: locale. See setOptions() for details.
Returns
boolean Returns true if a integer was found

Definition at line 721 of file Format.php.

722  {
723  if (!self::isNumber($value, $options)) {
724  return false;
725  }
726 
727  if (self::getInteger($value, $options) == self::getFloat($value, $options)) {
728  return true;
729  }
730 
731  return false;
732  }
$value
Definition: gender.phtml:16

◆ isNumber()

static isNumber (   $input,
array  $options = array() 
)
static

Checks if the input contains a normalized or localized number

Parameters
string$inputLocalized number string
array$optionsOptions: locale. See setOptions() for details.
Returns
boolean Returns true if a number was found

Definition at line 510 of file Format.php.

511  {
512  if (!self::_getUniCodeSupport()) {
513  trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE);
514  }
515 
516  $options = self::_checkOptions($options) + self::$_options;
517 
518  // Get correct signs for this locale
519  $symbols = Zend_Locale_Data::getList($options['locale'],'symbols');
520 
521  $regexs = Zend_Locale_Format::_getRegexForType('decimalnumber', $options);
522  $regexs = array_merge($regexs, Zend_Locale_Format::_getRegexForType('scientificnumber', $options));
523  if (!empty($input) && ($input[0] == $symbols['decimal'])) {
524  $input = 0 . $input;
525  }
526  foreach ($regexs as $regex) {
527  preg_match($regex, $input, $found);
528  if (isset($found[0])) {
529  return true;
530  }
531  }
532 
533  return false;
534  }
static getList($locale, $path, $value=false)
Definition: Data.php:318

◆ setOptions()

static setOptions ( array  $options = array())
static

Sets class wide options, if no option was given, the actual set options will be returned The 'precision' option of a value is used to truncate or stretch extra digits. -1 means not to touch the extra digits. The 'locale' option helps when parsing numbers and dates using separators and month names. The date format 'format_type' option selects between CLDR/ISO date format specifier tokens and PHP's date() tokens. The 'fix_date' option enables or disables heuristics that attempt to correct invalid dates. The 'number_format' option can be used to specify a default number format string The 'date_format' option can be used to specify a default date format string, but beware of using getDate(), checkDateFormat() and getTime() after using setOptions() with a 'format'. To use these four methods with the default date format for a locale, use array('date_format' => null, 'locale' => $locale) for their options.

Parameters
array$optionsArray of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false, locale = Zend_Locale | locale string, precision = whole number between -1 and 30
Exceptions
Zend_Locale_Exception
Returns
array if no option was given

Definition at line 64 of file Format.php.

65  {
66  self::$_options = self::_checkOptions($options) + self::$_options;
67  return self::$_options;
68  }

◆ toFloat()

static toFloat (   $value,
array  $options = array() 
)
static

Returns a locale formatted integer number Alias for toNumber()

Parameters
string$valueNumber to normalize
array$optionsOptions: locale, precision. See setOptions() for details.
Returns
string Locale formatted number

Definition at line 659 of file Format.php.

660  {
661  $options['number_format'] = Zend_Locale_Format::STANDARD;
662  return self::toNumber($value, $options);
663  }
$value
Definition: gender.phtml:16
static toNumber($value, array $options=array())
Definition: Format.php:300

◆ toInteger()

static toInteger (   $value,
array  $options = array() 
)
static

Returns a localized number

Parameters
string$valueNumber to normalize
array$optionsOptions: locale. See setOptions() for details.
Returns
string Locale formatted number

Definition at line 707 of file Format.php.

708  {
709  $options['precision'] = 0;
710  $options['number_format'] = Zend_Locale_Format::STANDARD;
711  return self::toNumber($value, $options);
712  }
$value
Definition: gender.phtml:16
static toNumber($value, array $options=array())
Definition: Format.php:300

◆ toNumber()

static toNumber (   $value,
array  $options = array() 
)
static

Returns a locale formatted number depending on the given options. The seperation and fraction sign is used from the set locale.

0.# -> 12345.12345 -> 12345.12345

0.00 -> 12345.12345 -> 12345.12

,##0.00 -> 12345.12345 -> 12,345.12

Parameters
string$valueLocalized number string
array$optionsOptions: number_format, locale, precision. See setOptions() for details.
Returns
string locale formatted number
Exceptions
Zend_Locale_Exception

Definition at line 300 of file Format.php.

301  {
302  // load class within method for speed
303  #require_once 'Zend/Locale/Math.php';
304 
307  $options = self::_checkOptions($options) + self::$_options;
308  $options['locale'] = (string) $options['locale'];
309 
310  // Get correct signs for this locale
311  $symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
312  $oenc = self::_getEncoding();
313  self::_setEncoding('UTF-8');
314 
315  // Get format
316  $format = $options['number_format'];
317  if ($format === null) {
318  $format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumber');
319  $format = self::_seperateFormat($format, $value, $options['precision']);
320 
321  if ($options['precision'] !== null) {
323  }
324  } else {
325  // seperate negative format pattern when available
326  $format = self::_seperateFormat($format, $value, $options['precision']);
327  if (strpos($format, '.')) {
328  if (is_numeric($options['precision'])) {
330  } else {
331  if (substr($format, iconv_strpos($format, '.') + 1, 3) == '###') {
332  $options['precision'] = null;
333  } else {
334  $options['precision'] = iconv_strlen(iconv_substr($format, iconv_strpos($format, '.') + 1,
335  iconv_strrpos($format, '0') - iconv_strpos($format, '.')));
336  $format = iconv_substr($format, 0, iconv_strpos($format, '.') + 1) . '###'
337  . iconv_substr($format, iconv_strrpos($format, '0') + 1);
338  }
339  }
340  } else {
342  $options['precision'] = 0;
343  }
345  }
346 
347  if (iconv_strpos($format, '0') === false) {
348  self::_setEncoding($oenc);
349  #require_once 'Zend/Locale/Exception.php';
350  throw new Zend_Locale_Exception('Wrong format... missing 0');
351  }
352 
353  // get number parts
354  $pos = iconv_strpos($value, '.');
355  if ($pos !== false) {
356  if ($options['precision'] === null) {
357  $precstr = iconv_substr($value, $pos + 1);
358  } else {
359  $precstr = iconv_substr($value, $pos + 1, $options['precision']);
360  if (iconv_strlen($precstr) < $options['precision']) {
361  $precstr = $precstr . str_pad("0", ($options['precision'] - iconv_strlen($precstr)), "0");
362  }
363  }
364  } else {
365  if ($options['precision'] > 0) {
366  $precstr = str_pad("0", ($options['precision']), "0");
367  }
368  }
369 
370  if ($options['precision'] === null) {
371  if (isset($precstr)) {
372  $options['precision'] = iconv_strlen($precstr);
373  } else {
374  $options['precision'] = 0;
375  }
376  }
377 
378  // get fraction and format lengths
379  if (strpos($value, '.') !== false) {
380  $number = substr((string) $value, 0, strpos($value, '.'));
381  } else {
382  $number = $value;
383  }
384 
386  $prec = Zend_Locale_Math::floatalize($prec);
387  $prec = Zend_Locale_Math::normalize($prec);
388  if (iconv_strpos($prec, '-') !== false) {
389  $prec = iconv_substr($prec, 1);
390  }
391 
392  if (($prec == 0) and ($options['precision'] > 0)) {
393  $prec = "0.0";
394  }
395 
396  if (($options['precision'] + 2) > iconv_strlen($prec)) {
397  $prec = str_pad((string) $prec, $options['precision'] + 2, "0", STR_PAD_RIGHT);
398  }
399 
400  if (iconv_strpos($number, '-') !== false) {
401  $number = iconv_substr($number, 1);
402  }
403  $group = iconv_strrpos($format, ',');
404  $group2 = iconv_strpos ($format, ',');
405  $point = iconv_strpos ($format, '0');
406  // Add fraction
407  $rest = "";
408  if (iconv_strpos($format, '.')) {
409  $rest = iconv_substr($format, iconv_strpos($format, '.') + 1);
410  $length = iconv_strlen($rest);
411  for($x = 0; $x < $length; ++$x) {
412  if (($rest[0] == '0') || ($rest[0] == '#')) {
413  $rest = iconv_substr($rest, 1);
414  }
415  }
416  $format = iconv_substr($format, 0, iconv_strlen($format) - iconv_strlen($rest));
417  }
418 
419  if ($options['precision'] == '0') {
420  if (iconv_strrpos($format, '-') != 0) {
421  $format = iconv_substr($format, 0, $point)
422  . iconv_substr($format, iconv_strrpos($format, '#') + 2);
423  } else {
424  $format = iconv_substr($format, 0, $point);
425  }
426  } else {
427  $format = iconv_substr($format, 0, $point) . $symbols['decimal']
428  . iconv_substr($prec, 2);
429  }
430 
431  $format .= $rest;
432  // Add seperation
433  if ($group == 0) {
434  // no seperation
435  $format = $number . iconv_substr($format, $point);
436  } else if ($group == $group2) {
437  // only 1 seperation
438  $seperation = ($point - $group);
439  for ($x = iconv_strlen($number); $x > $seperation; $x -= $seperation) {
440  if (iconv_substr($number, 0, $x - $seperation) !== "") {
441  $number = iconv_substr($number, 0, $x - $seperation) . $symbols['group']
442  . iconv_substr($number, $x - $seperation);
443  }
444  }
445  $format = iconv_substr($format, 0, iconv_strpos($format, '#')) . $number . iconv_substr($format, $point);
446  } else {
447 
448  // 2 seperations
449  if (iconv_strlen($number) > ($point - $group)) {
450  $seperation = ($point - $group);
451  $number = iconv_substr($number, 0, iconv_strlen($number) - $seperation) . $symbols['group']
452  . iconv_substr($number, iconv_strlen($number) - $seperation);
453 
454  if ((iconv_strlen($number) - 1) > ($point - $group + 1)) {
455  $seperation2 = ($group - $group2 - 1);
456  for ($x = iconv_strlen($number) - $seperation2 - 2; $x > $seperation2; $x -= $seperation2) {
457  $number = iconv_substr($number, 0, $x - $seperation2) . $symbols['group']
458  . iconv_substr($number, $x - $seperation2);
459  }
460  }
461 
462  }
463  $format = iconv_substr($format, 0, iconv_strpos($format, '#')) . $number . iconv_substr($format, $point);
464  }
465  // set negative sign
466  if (call_user_func(Zend_Locale_Math::$comp, $value, 0, $options['precision']) < 0) {
467  if (iconv_strpos($format, '-') === false) {
468  $format = $symbols['minus'] . $format;
469  } else {
470  $format = str_replace('-', $symbols['minus'], $format);
471  }
472  }
473 
474  self::_setEncoding($oenc);
475  return (string) $format;
476  }
static $sub
Definition: Math.php:41
static $comp
Definition: Math.php:45
static getList($locale, $path, $value=false)
Definition: Data.php:318
static floatalize($value)
Definition: Math.php:144
$number
Definition: details.phtml:22
static getContent($locale, $path, $value=false)
Definition: Data.php:968
$group
Definition: sections.phtml:16
$value
Definition: gender.phtml:16
$format
Definition: list.phtml:12
$pos
Definition: list.phtml:42
static _getEncoding()
Definition: Format.php:1318
static _setEncoding($encoding)
Definition: Format.php:1334
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65

Field Documentation

◆ STANDARD

const STANDARD = 'auto'

Definition at line 37 of file Format.php.


The documentation for this class was generated from the following file: