DatetimeParser
class DatetimeParser (View source)
Parser for date and time.
Constants
PATTERN_MATCH_STRICT_TIMEZONE_ABBREVIATION |
Regex pattern for matching abbreviated timezones, like GMT, CEST, etc. Two versions for strict and lenient matching modes. |
PATTERN_MATCH_LENIENT_TIMEZONE_ABBREVIATION |
|
PATTERN_MATCH_STRICT_TIMEZONE_TZ |
Regex pattern for matching TZ database timezones, like Europe/London. Two versions for strict and lenient matching modes. |
PATTERN_MATCH_LENIENT_TIMEZONE_TZ |
|
Properties
protected DatesReader | $datesReader |
Methods
Returns dateTime parsed by custom format (string provided in parameter).
Parses dateTime with format string for date and time defined in CLDR for particular locale.
Parses date and / or time using parsed format, in strict or lenient mode.
Parses date and / or time in strict mode.
Parses date and / or time in lenient mode.
Extracts one or two-digit number from the beginning of the string.
Extracts and returns first integer number encountered in provided string.
Details
void
injectDatesReader(DatesReader $datesReader)
No description
mixed
parseDatetimeWithCustomPattern(string $datetimeToParse, string $format, Locale $locale, bool $strictMode = true)
Returns dateTime parsed by custom format (string provided in parameter).
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.
mixed
parseDate(string $dateToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, bool $strictMode = true)
Parses date with format string for date defined in CLDR for particular locale.
mixed
parseTime(string $timeToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, bool $strictMode = true)
Parses time with format string for time defined in CLDR for particular locale.
mixed
parseDateAndTime(string $dateAndTimeToParse, Locale $locale, string $formatLength = DatesReader::FORMAT_LENGTH_DEFAULT, bool $strictMode = true)
Parses dateTime with format string for date and time defined in CLDR for particular locale.
protected mixed
doParsingWithParsedFormat(string $datetimeToParse, array $parsedFormat, array $localizedLiterals, bool $strictMode)
Parses date and / or time using parsed format, in strict or lenient mode.
protected array
doParsingInStrictMode(string $datetimeToParse, array $parsedFormat, array $localizedLiterals)
Parses date and / or time in strict mode.
protected array
doParsingInLenientMode(string $datetimeToParse, array $parsedFormat, array $localizedLiterals)
Parses date and / or time in lenient mode.
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')
protected int
extractAndCheckNumber(string $datetimeToParse, bool $isTwoDigits, int $minValue, int $maxValue)
Extracts one or two-digit number from the beginning of the string.
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 string
extractNumberAndGetPosition(string $datetimeToParse, int $position)
Extracts and returns first integer number encountered in provided string.
Searches for first digit and extracts all adjacent digits. Also returns position of first digit in string.