PHP Class Neos\Flow\I18n\Parser\DatetimeParser

Datei anzeigen Open project: neos/flow-development-collection

Protected Properties

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

Public Methods

Method Description
injectDatesReader ( DatesReader $datesReader ) : void
parseDate ( string $dateToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed Parses date with format string for date defined in CLDR for particular locale.
parseDateAndTime ( string $dateAndTimeToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed Parses dateTime with format string for date and time defined in CLDR for particular locale.
parseDatetimeWithCustomPattern ( string $datetimeToParse, string $format, Locale $locale, boolean $strictMode = true ) : mixed Returns dateTime parsed by custom format (string provided in parameter).
parseTime ( string $timeToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed Parses time with format string for time defined in CLDR for particular locale.

Protected Methods

Method Description
doParsingInLenientMode ( string $datetimeToParse, array $parsedFormat, array $localizedLiterals ) : array Parses date and / or time in lenient mode.
doParsingInStrictMode ( string $datetimeToParse, array $parsedFormat, array $localizedLiterals ) : array Parses date and / or time in strict mode.
doParsingWithParsedFormat ( string $datetimeToParse, array $parsedFormat, array $localizedLiterals, boolean $strictMode ) : mixed Parses date and / or time using parsed format, in strict or lenient mode.
extractAndCheckNumber ( string $datetimeToParse, boolean $isTwoDigits, integer $minValue, integer $maxValue ) : integer Extracts one or two-digit number from the beginning of the string.
extractNumberAndGetPosition ( string $datetimeToParse, integer &$position ) : string Extracts and returns first integer number encountered in provided string.

Method Details

doParsingInLenientMode() protected method

Algorithm assumptions: - ignore all literals - order of elements in parsed format is important - length of subformat is not strictly checked (eg. 'h' and 'hh') - number must be in range in order to be accepted (eg. 1-12 for month) - some format fallback substitutions can be done (eg. 'Jan' for 'January')
See also: DatesReader
protected doParsingInLenientMode ( string $datetimeToParse, array $parsedFormat, array $localizedLiterals ) : array
$datetimeToParse string Date/time to be parsed
$parsedFormat array Format parsed by DatesReader
$localizedLiterals array Array of date / time literals from CLDR
return array Array of parsed date and / or time elements (can be array of NULLs if nothing was parsed)

doParsingInStrictMode() protected method

Parses date and / or time in strict mode.
See also: DatesReader
protected doParsingInStrictMode ( string $datetimeToParse, array $parsedFormat, array $localizedLiterals ) : array
$datetimeToParse string Date/time to be parsed
$parsedFormat array Format parsed by DatesReader
$localizedLiterals array Array of date / time literals from CLDR
return array Array of parsed date and / or time elements, FALSE on failure

doParsingWithParsedFormat() protected method

Parses date and / or time using parsed format, in strict or lenient mode.
protected doParsingWithParsedFormat ( string $datetimeToParse, array $parsedFormat, array $localizedLiterals, boolean $strictMode ) : mixed
$datetimeToParse string Date/time to be parsed
$parsedFormat array Parsed format (from DatesReader)
$localizedLiterals array Array of date / time literals from CLDR
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Array of parsed date and / or time elements, FALSE on failure

extractAndCheckNumber() protected method

If the number has certainly two digits, $isTwoDigits can be set to TRUE so no additional checking is done (this implies from some date/time formats, like 'hh'). Number is also checked for constraints: minimum and maximum value.
protected extractAndCheckNumber ( string $datetimeToParse, boolean $isTwoDigits, integer $minValue, integer $maxValue ) : integer
$datetimeToParse string Date/time to be parsed
$isTwoDigits boolean TRUE if number has surely two digits, FALSE if it has one or two digits
$minValue integer
$maxValue integer
return integer Parsed number

extractNumberAndGetPosition() protected method

Searches for first digit and extracts all adjacent digits. Also returns position of first digit in string.
protected extractNumberAndGetPosition ( string $datetimeToParse, integer &$position ) : string
$datetimeToParse string String to search number in
$position integer Index of first digit in string
return string Extracted number

injectDatesReader() public method

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

parseDate() public method

Parses date with format string for date defined in CLDR for particular locale.
public parseDate ( string $dateToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed
$dateToParse string date to be parsed
$locale Neos\Flow\I18n\Locale
$formatLength string One of: full, long, medium, short, or 'default' in order to use default length from CLDR
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Array of parsed date elements, FALSE on failure

parseDateAndTime() public method

Parses dateTime with format string for date and time defined in CLDR for particular locale.
public parseDateAndTime ( string $dateAndTimeToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed
$dateAndTimeToParse string Date and time to be parsed
$locale Neos\Flow\I18n\Locale
$formatLength string One of: full, long, medium, short, or 'default' in order to use default length from CLDR
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Array of parsed date and time elements, FALSE on failure

parseDatetimeWithCustomPattern() public method

Format must obey syntax defined in CLDR specification, excluding unimplemented features (see documentation for DatesReader class). Format is remembered in cache and won't be parsed again for some time.
See also: DatesReader
public parseDatetimeWithCustomPattern ( string $datetimeToParse, string $format, Locale $locale, boolean $strictMode = true ) : mixed
$datetimeToParse string Date/time to be parsed
$format string Format string
$locale Neos\Flow\I18n\Locale A locale used for finding literals array
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Array of parsed date / time elements, FALSE on failure

parseTime() public method

Parses time with format string for time defined in CLDR for particular locale.
public parseTime ( string $timeToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed
$timeToParse string Time to be parsed
$locale Neos\Flow\I18n\Locale
$formatLength string One of: full, long, medium, short, or 'default' in order to use default length from CLDR
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Array of parsed time elements, FALSE on failure

Property Details

$datesReader protected_oe property

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