PHP Class Neos\Flow\I18n\Formatter\DatetimeFormatter

This is not full implementation of features from CLDR. These are missing: - support for other calendars than Gregorian - rules for displaying timezone names are simplified - some less frequently used format characters are not supported
Inheritance: implements Neos\Flow\I18n\Formatter\FormatterInterface
Exibir arquivo Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$datesReader Neos\Flow\I18n\Cldr\Reader\DatesReader

Public Methods

Method Description
format ( mixed $value, Locale $locale, array $styleProperties = [] ) : string Formats provided value using optional style properties
formatDate ( DateTimeInterface $date, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT ) : string Formats date with format string for date defined in CLDR for particular locale.
formatDateTime ( DateTimeInterface $dateTime, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT ) : string Formats dateTime with format string for date and time defined in CLDR for particular locale.
formatDateTimeWithCustomPattern ( DateTimeInterface $dateTime, string $format, Locale $locale ) : string Returns dateTime formatted by custom format, string provided in parameter.
formatTime ( DateTimeInterface $time, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT ) : string Formats time with format string for time defined in CLDR for particular locale.
injectDatesReader ( DatesReader $datesReader ) : void

Protected Methods

Method Description
doFormattingForSubpattern ( DateTimeInterface $dateTime, string $subformat, array $localizedLiterals ) : string Formats date or time element according to the subpattern provided.
doFormattingWithParsedFormat ( DateTimeInterface $dateTime, array $parsedFormat, array $localizedLiterals ) : string Formats provided dateTime object.
padString ( string $string, integer $formatLength ) : string Pads given string to the specified length with zeros.

Method Details

doFormattingForSubpattern() protected method

Returns a string with formatted one "part" of DateTime object (seconds, day, month etc). Not all pattern symbols defined in CLDR are supported; some of the rules are simplified. Please see the documentation for DatesReader for details. Cases in the code are ordered in such way that probably mostly used are on the top (but they are also grouped by similarity).
See also: Neos\Flow\I18n\Cldr\Reader\DatesReader
protected doFormattingForSubpattern ( DateTimeInterface $dateTime, string $subformat, array $localizedLiterals ) : string
$dateTime DateTimeInterface PHP object representing particular point in time
$subformat string One element of format string (e.g., 'yyyy', 'mm', etc)
$localizedLiterals array Array of date / time literals from CLDR
return string Formatted part of date / time

doFormattingWithParsedFormat() protected method

Format rules defined in $parsedFormat array are used. Localizable literals are replaced with elements from $localizedLiterals array.
protected doFormattingWithParsedFormat ( DateTimeInterface $dateTime, array $parsedFormat, array $localizedLiterals ) : string
$dateTime DateTimeInterface PHP object representing particular point in time
$parsedFormat array An array describing format (as in $parsedFormats property)
$localizedLiterals array An array with literals to use (as in $localizedLiterals property)
return string Formatted date / time

format() public method

Formats provided value using optional style properties
public format ( mixed $value, Locale $locale, array $styleProperties = [] ) : string
$value mixed Formatter-specific variable to format (can be integer, \DateTime, etc)
$locale Neos\Flow\I18n\Locale Locale to use
$styleProperties array Integer-indexed array of formatter-specific style properties (can be empty)
return string String representation of $value provided, or (string)$value

formatDate() public method

Formats date with format string for date defined in CLDR for particular locale.
public formatDate ( DateTimeInterface $date, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT ) : string
$date DateTimeInterface PHP object representing particular point in time
$locale Neos\Flow\I18n\Locale
$formatLength string One of DatesReader FORMAT_LENGTH constants
return string Formatted date

formatDateTime() public method

First date and time are formatted separately, and then dateTime format from CLDR is used to place date and time in correct order.
public formatDateTime ( DateTimeInterface $dateTime, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT ) : string
$dateTime DateTimeInterface PHP object representing particular point in time
$locale Neos\Flow\I18n\Locale
$formatLength string One of DatesReader FORMAT_LENGTH constants
return string Formatted date and time

formatDateTimeWithCustomPattern() public method

Format must obey syntax defined in CLDR specification, excluding unimplemented features (see documentation for DatesReader class). Format is remembered in this classes cache and won't be parsed again for some time.
See also: Neos\Flow\I18n\Cldr\Reader\DatesReader
public formatDateTimeWithCustomPattern ( DateTimeInterface $dateTime, string $format, Locale $locale ) : string
$dateTime DateTimeInterface PHP object representing particular point in time
$format string Format string
$locale Neos\Flow\I18n\Locale A locale used for finding literals array
return string Formatted date / time. Unimplemented subformats in format string will be silently ignored

formatTime() public method

Formats time with format string for time defined in CLDR for particular locale.
public formatTime ( DateTimeInterface $time, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT ) : string
$time DateTimeInterface PHP object representing particular point in time
$locale Neos\Flow\I18n\Locale
$formatLength string One of DatesReader FORMAT_LENGTH constants
return string Formatted time

injectDatesReader() public method

public injectDatesReader ( DatesReader $datesReader ) : void
$datesReader Neos\Flow\I18n\Cldr\Reader\DatesReader
return void

padString() protected method

Pads given string to the specified length with zeros.
protected padString ( string $string, integer $formatLength ) : string
$string string
$formatLength integer
return string Padded string (can be unchanged if $formatLength is lower than length of string)

Property Details

$datesReader protected_oe property

protected DatesReader,Neos\Flow\I18n\Cldr\Reader $datesReader
return Neos\Flow\I18n\Cldr\Reader\DatesReader