protected static genCalList ( string $unit = 'day', boolean $abbr = false, integer $start = 1, string $case = null ) : array | ||
$unit | string | whether 'day' or 'month' |
$abbr | boolean | whether to return abbreviated day or month |
$start | integer | the first day or month to set. Defaults to `1`. |
$case | string | whether 'upper', lower', or null. If null, then the initcap case will be used. |
리턴 | array | list of days or months |
protected static function genCalList($unit = 'day', $abbr = false, $start = 1, $case = null)
{
$source = $unit == 'month' ? static::months() : static::days();
$total = count($source);
if ($start < 1 || $start > $total) {
throw new InvalidConfigException("The start '{$unit}' must be between 1 and {$total}.");
}
$converted = [];
foreach ($source as $key => $value) {
$data = $abbr ? substr($value, 0, 3) : $value;
if ($case == 'upper') {
$data = strtoupper($data);
} elseif ($case == 'lower') {
$data = strtolower($data);
}
if ($start == 1) {
$i = $key;
} else {
$i = $key - $start + 1;
if ($i < 1) {
$i += $total;
}
}
$converted[$i] = $data;
}
return ksort($converted) ? $converted : $source;
}