public static function timeList($unit, $interval = 1, $from = 0, $to = null, $padZero = true)
{
if ($unit == 'hour') {
$maxTo = 23;
} elseif ($unit == 'min' || $unit == 'sec') {
$maxTo = 59;
} elseif ($unit == 'ms') {
$maxTo = 999;
} else {
throw new InvalidConfigException("Invalid time unit passed. Must be 'hour', 'min', 'sec', or 'ms'.");
}
if ($interval < 1) {
throw new InvalidConfigException("Invalid time interval '{$interval}'. Must be greater than 0.");
}
if (empty($to)) {
$to = $maxTo;
}
if ($to > $maxTo) {
throw new InvalidConfigException("The '{$unit} to' cannot exceed {$maxTo}.");
}
if ($from < 0 || $from > $to) {
throw new InvalidConfigException("The '{$unit} from' must lie between {$from} and {$to}.");
}
$data = range($from, $to, $interval);
if (!$padZero) {
return $data;
}
$out = [];
$pad = strlen($maxTo . '');
foreach ($data as $key => $value) {
$out[$key] = str_pad($value, $pad, '0', STR_PAD_LEFT);
}
return $out;
}