protected function prepareDateAndTimeFormat($format, Locale $locale, $formatLength)
{
$parsedFormatForDate = $this->parseFormatFromCldr($locale, 'date', $formatLength);
$parsedFormatForTime = $this->parseFormatFromCldr($locale, 'time', $formatLength);
$positionOfTimePlaceholder = strpos($format, '{0}');
$positionOfDatePlaceholder = strpos($format, '{1}');
if ($positionOfTimePlaceholder < $positionOfDatePlaceholder) {
$positionOfFirstPlaceholder = $positionOfTimePlaceholder;
$positionOfSecondPlaceholder = $positionOfDatePlaceholder;
$firstParsedFormat = $parsedFormatForTime;
$secondParsedFormat = $parsedFormatForDate;
} else {
$positionOfFirstPlaceholder = $positionOfDatePlaceholder;
$positionOfSecondPlaceholder = $positionOfTimePlaceholder;
$firstParsedFormat = $parsedFormatForDate;
$secondParsedFormat = $parsedFormatForTime;
}
$parsedFormat = [];
if ($positionOfFirstPlaceholder !== 0) {
// Add everything before placeholder as literal
$parsedFormat[] = [substr($format, 0, $positionOfFirstPlaceholder)];
}
$parsedFormat = array_merge($parsedFormat, $firstParsedFormat);
if ($positionOfSecondPlaceholder - $positionOfFirstPlaceholder > 3) {
// There is something between the placeholders
$parsedFormat[] = [substr($format, $positionOfFirstPlaceholder + 3, $positionOfSecondPlaceholder - ($positionOfFirstPlaceholder + 3))];
}
$parsedFormat = array_merge($parsedFormat, $secondParsedFormat);
if ($positionOfSecondPlaceholder !== strlen($format) - 1) {
// Add everything before placeholder as literal
$parsedFormat[] = [substr($format, $positionOfSecondPlaceholder + 3)];
}
return $parsedFormat;
}