protected function doFormattingForSubpattern(\DateTimeInterface $dateTime, $subformat, array $localizedLiterals)
{
$formatLengthOfSubformat = strlen($subformat);
switch ($subformat[0]) {
case 'h':
return $this->padString($dateTime->format('g'), $formatLengthOfSubformat);
case 'H':
return $this->padString($dateTime->format('G'), $formatLengthOfSubformat);
case 'K':
$hour = (int) $dateTime->format('g');
if ($hour === 12) {
$hour = 0;
}
return $this->padString($hour, $formatLengthOfSubformat);
case 'k':
$hour = (int) $dateTime->format('G');
if ($hour === 0) {
$hour = 24;
}
return $this->padString($hour, $formatLengthOfSubformat);
case 'a':
return $localizedLiterals['dayPeriods']['format']['wide'][$dateTime->format('a')];
case 'm':
return $this->padString((int) $dateTime->format('i'), $formatLengthOfSubformat);
case 's':
return $this->padString((int) $dateTime->format('s'), $formatLengthOfSubformat);
case 'S':
return (string) round($dateTime->format('u'), $formatLengthOfSubformat);
case 'd':
return $this->padString($dateTime->format('j'), $formatLengthOfSubformat);
case 'D':
return $this->padString((int) ($dateTime->format('z') + 1), $formatLengthOfSubformat);
case 'F':
return (int) (($dateTime->format('j') + 6) / 7);
case 'M':
case 'L':
$month = (int) $dateTime->format('n');
$formatType = $subformat[0] === 'L' ? 'stand-alone' : 'format';
if ($formatLengthOfSubformat <= 2) {
return $this->padString($month, $formatLengthOfSubformat);
} elseif ($formatLengthOfSubformat === 3) {
return $localizedLiterals['months'][$formatType]['abbreviated'][$month];
} elseif ($formatLengthOfSubformat === 4) {
return $localizedLiterals['months'][$formatType]['wide'][$month];
} else {
return $localizedLiterals['months'][$formatType]['narrow'][$month];
}
case 'y':
$year = (int) $dateTime->format('Y');
if ($formatLengthOfSubformat === 2) {
$year %= 100;
}
return $this->padString($year, $formatLengthOfSubformat);
case 'E':
$day = strtolower($dateTime->format('D'));
if ($formatLengthOfSubformat <= 3) {
return $localizedLiterals['days']['format']['abbreviated'][$day];
} elseif ($formatLengthOfSubformat === 4) {
return $localizedLiterals['days']['format']['wide'][$day];
} else {
return $localizedLiterals['days']['format']['narrow'][$day];
}
case 'w':
return $this->padString($dateTime->format('W'), $formatLengthOfSubformat);
case 'W':
return (string) (((int) $dateTime->format('W') - 1) % 4 + 1);
case 'Q':
case 'q':
$quarter = (int) ($dateTime->format('n') / 3.1) + 1;
$formatType = $subformat[0] === 'q' ? 'stand-alone' : 'format';
if ($formatLengthOfSubformat <= 2) {
return $this->padString($quarter, $formatLengthOfSubformat);
} elseif ($formatLengthOfSubformat === 3) {
return $localizedLiterals['quarters'][$formatType]['abbreviated'][$quarter];
} else {
return $localizedLiterals['quarters'][$formatType]['wide'][$quarter];
}
case 'G':
$era = (int) ($dateTime->format('Y') > 0);
if ($formatLengthOfSubformat <= 3) {
return $localizedLiterals['eras']['eraAbbr'][$era];
} elseif ($formatLengthOfSubformat === 4) {
return $localizedLiterals['eras']['eraNames'][$era];
} else {
return $localizedLiterals['eras']['eraNarrow'][$era];
}
case 'v':
case 'z':
if ($formatLengthOfSubformat <= 3) {
return $dateTime->format('T');
} else {
return $dateTime->format('e');
}
case 'Y':
case 'u':
case 'l':
case 'g':
case 'e':
case 'c':
case 'A':
case 'Z':
case 'V':
// Silently ignore unsupported formats
return '';
default:
throw new InvalidArgumentException('Unexpected format symbol, "' . $subformat[0] . '" detected for date / time formatting.', 1276106678);
}
}