[ 'h' => '%l', 'm' => '%M', 'p' => '%P', ], 'hourSeparator' => ':', 'rangeSeparator' => ' - ', 'showZeroMinutes' => false, 'showLastAmPmOnly' => true, ]; $options = array_replace_recursive($options, $params); $getTimeFormat = function ($time, $hasAmPm = true) use ($options) { $part = &$options['partsFormat']; $format = $part['h']; if ($options['showZeroMinutes'] || 0 != $time['minutes']) { $format .= $options['hourSeparator'] . $part['m']; } if ($hasAmPm) { $format .= ' ' . $part['p']; } return $format; }; $formatTimeRange = function ($startTime, $endTime) use ($options, &$getTimeFormat) { $start = getdate($startTime); if (empty($endTime)) { return strftime($getTimeFormat($start), $startTime); } $end = getdate($endTime); $parts = []; $hasStartAmPm = !$options['showLastAmPmOnly'] || ($start['hours'] < 12 && $end['hours'] >= 12); $parts[] = strftime($getTimeFormat($start, $hasStartAmPm), $startTime); $parts[] = strftime($getTimeFormat($end), $endTime); return implode($options['rangeSeparator'], $parts); }; $startTime = strtotime($params['start']); $endTime = empty($params['end']) ? null : strtotime($params['end']); return $formatTimeRange($startTime, $endTime); }