API Documentation

Locale/Format.php

Includes Classes 
category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Locale
subpackage
Format
version
$Id: Format.php 22684 2010-07-26 15:45:14Z alexander $
Classes
Zend_Locale_Format

Description

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

Zend_Locale_Format

category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Locale
subpackage
Format
Constants
STANDARD
Properties
$_options
Methods
setOptions
_checkOptions
convertNumerals
getNumber
toNumber
_seperateFormat
isNumber
_getRegexForType
getFloat
toFloat
isFloat
getInteger
toInteger
isInteger
convertPhpToIsoFormat
_parseDate
_replaceMonth
getDateFormat
getDate
checkDateFormat
getTimeFormat
getTime
getDateTimeFormat
getDateTime

Description

Constants

STANDARD

 STANDARD = 'auto'

Details

value
auto

Properties

$_options

 $_options = 'array'

Details

visibility
private
default
array
final
false
static
true

Methods

_checkOptions

_checkOptions( array $options = array ) : Options

Internal function for checking the options array of proper input values See {@link setOptions()} for details.

Arguments
$options
array
Array 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
Output
Options
array if no option was given
Details
visibility
private
final
false
static
true
throws

_getRegexForType

_getRegexForType( string $type,  $options ) : string

Internal method to convert cldr number syntax into regex

Arguments
$type
string
$options
Output
string
Details
visibility
private
final
false
static
true

_parseDate

_parseDate( string $date, array $options ) : array

Parse date and split in named array fields

Arguments
$date
string
Date string to parse
$options
array
Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
Output
array
Possible array members: day, month, year, hour, minute, second, fixed, format
Details
visibility
private
final
false
static
true

_replaceMonth

_replaceMonth( string $number, array $monthlist ) : int|false

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

Arguments
$number
string
Date string (modified)
$monthlist
array
List of month names
Output
int|false
Position of replaced string (false if nothing replaced)
Details
visibility
protected
final
false
static
true

_seperateFormat

_seperateFormat(  $format,  $value,  $precision ) :
Arguments
$format
$value
$precision
Details
visibility
private
final
false
static
true

checkDateFormat

checkDateFormat( string $date, array $options = array ) : boolean

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()

Arguments
$date
string
Date string
$options
array
Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
Output
boolean
Details
visibility
public
final
false
static
true

convertNumerals

convertNumerals( string $input, string $from, string $to = null ) : string

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'

Arguments
$input
string
String to convert
$from
string
Script to parse, see {@link Zend_Locale::getScriptList()} for details.
$to
string
OPTIONAL Script to convert to
Output
string
Returns the converted input
Details
visibility
public
final
false
static
true
throws

convertPhpToIsoFormat

convertPhpToIsoFormat( string $format ) : string

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

Arguments
$format
string
Format string in PHP's date format
Output
string
Format string in ISO format
Details
visibility
public
final
false
static
true

getDate

getDate( string $date, array $options = array ) : array

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'.

Arguments
$date
string
Date string
$options
array
Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
Output
array
Possible array members: day, month, year, hour, minute, second, fixed, format
Details
visibility
public
final
false
static
true

getDateFormat

getDateFormat( string|Zend_Locale $locale = null ) : string

Returns the default date format for $locale.

Arguments
$locale
stringZend_Locale
OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
Output
string
format
Details
visibility
public
final
false
static
true
throws
throws an exception when locale data is broken

getDateTime

getDateTime( string $datetime, array $options = array ) : array

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:m: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.

Arguments
$datetime
string
DateTime string
$options
array
Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
Output
array
Possible array members: day, month, year, hour, minute, second, fixed, format
Details
visibility
public
final
false
static
true

getDateTimeFormat

getDateTimeFormat( string|Zend_Locale $locale = null ) : string

Returns the default datetime format for $locale.

Arguments
$locale
stringZend_Locale
OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
Output
string
format
Details
visibility
public
final
false
static
true

getFloat

getFloat(  $input, array $options = array ) : float

Alias for getNumber

Arguments
$input
$options
array
Options: locale, precision. See {@link setOptions()} for details.
Output
float
Details
visibility
public
final
false
static
true

getInteger

getInteger( string $input, array $options = array ) : integer

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+'

Arguments
$input
string
Input string to parse for numbers
$options
array
Options: locale. See {@link setOptions()} for details.
Output
integer
Returns the extracted number
Details
visibility
public
final
false
static
true

getNumber

getNumber( string $input, array $options = array ) : string

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

Arguments
$input
string
Input string to parse for numbers
$options
array
Options: locale, precision. See {@link setOptions()} for details.
Output
string
Returns the extracted number
Details
visibility
public
final
false
static
true
throws

getTime

getTime( string $time, array $options = array ) : array

Returns an array with 'hour', 'minute', and 'second' elements extracted from $time according to the order described in $format. For a format of 'H:m: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.

Arguments
$time
string
Time string
$options
array
Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
Output
array
Possible array members: day, month, year, hour, minute, second, fixed, format
Details
visibility
public
final
false
static
true

getTimeFormat

getTimeFormat( string|Zend_Locale $locale = null ) : string

Returns the default time format for $locale.

Arguments
$locale
stringZend_Locale
OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT')
Output
string
format
Details
visibility
public
final
false
static
true

isFloat

isFloat(  $value, array $options = array ) : boolean

Returns if a float was found Alias for isNumber()

Arguments
$value
$options
array
Options: locale. See {@link setOptions()} for details.
Output
boolean
Returns true if a number was found
Details
visibility
public
final
false
static
true

isInteger

isInteger(  $value, array $options = array ) : boolean

Returns if a integer was found

Arguments
$value
$options
array
Options: locale. See {@link setOptions()} for details.
Output
boolean
Returns true if a integer was found
Details
visibility
public
final
false
static
true

isNumber

isNumber( string $input, array $options = array ) : boolean

Checks if the input contains a normalized or localized number

Arguments
$input
string
Localized number string
$options
array
Options: locale. See {@link setOptions()} for details.
Output
boolean
Returns true if a number was found
Details
visibility
public
final
false
static
true

setOptions

setOptions( array $options = array ) : Options

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.

Arguments
$options
array
Array 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
Output
Options
array if no option was given
Details
visibility
public
final
false
static
true
throws

toFloat

toFloat( string $value, array $options = array ) : string

Returns a locale formatted integer number Alias for toNumber()

Arguments
$value
string
Number to normalize
$options
array
Options: locale, precision. See {@link setOptions()} for details.
Output
string
Locale formatted number
Details
visibility
public
final
false
static
true

toInteger

toInteger( string $value, array $options = array ) : string

Returns a localized number

Arguments
$value
string
Number to normalize
$options
array
Options: locale. See {@link setOptions()} for details.
Output
string
Locale formatted number
Details
visibility
public
final
false
static
true

toNumber

toNumber(  $value, array $options = array ) : string

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

Arguments
$value
$options
array
Options: number_format, locale, precision. See {@link setOptions()} for details.
Output
string
locale formatted number
Details
visibility
public
final
false
static
true
throws
Documentation was generated by DocBlox.